Solved

Delphi: Search Method -- Memo.Lines to Binary Record file

Posted on 2007-04-07
5
1,658 Views
Last Modified: 2013-11-23
Hi everyone, you'll excuse my poor programming skills but i plane to import some computernames and there server names into my binary file already created.
If computer name already exists in the binary record, then it pops up something. Else, it Add's it to the Binary file with it's appropriate server.

I wanted (or open to  use something else than a Memo Text box)  to use Memo text to copy/paste my text file, then execute the Search routine but my code is so poor that i came here :)
Exemple of Data i want to import into my Record file:
WW0003DD000  SRV001DT003
WW0003DD002  ORI001DT022
WW0003DD003  FFF001DT013

Idea of the Code...
type Elements =record
                PC_Name,Local_SRV,Print_SRV:string[15];
               end;

var
  DBase : Elements;
  f : file of Elements;
  FileName:string;
  t:integer;

procedure TForm4.Button1Click(Sender: TObject);
var i,n:integer;
begin
 assignfile(f,FileName);
 {$i-}reset(f);{$i+}
 i:=0;
 n:=0;
 for n:=0 to memo1.Lines.count -1 do
  Begin
    with Dbase do
      Begin
       seek(f,0);
       read(f,Dbase);
       While not eof(f) do
         Begin
          Repeat
            seek(f,i);
            read(f,Dbase);
            showmessage(Memo1.Lines[n] +' PC not Found!! !');
            i:=i+1;
          until ( memo1.Lines[n] = PC_Name );

          Begin
           showmessage('PC Found ' +Memo1.Lines[n]+'....'+inttostr(n));
           i:=0;
           seek(f,i);
           read(f,Dbase);
          end;
         end;
      end;
   end;
       showmessage('Exit of the file');
      exit;
end;

If you guys got any other search method it yould be so much apreciated.   Thank you.
0
Comment
Question by:mediteranio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
calinutz earned 250 total points
ID: 18870386
Why don't you use an xml file to store your data in it?
It's easyer to work with... plain database use.

Use ClientDataset to store and retrieve data from your records.

Tutorial for using Client DataSet can be found here:
http://delphi.about.com/od/usedbvcl/a/tclientdataset.htm

It's a better way to do it

Regards
0
 

Author Comment

by:mediteranio
ID: 18870547
You are right Calinutz. I'm checking this. It's all new for me :)

Thank you.
0
 

Author Comment

by:mediteranio
ID: 18921385
I did a small program who creates an XML TDocument file. Creating a file with some data i have no trouble.  But when i want to import Data from my XML, i'm having some hard time.  You guys know how to get data from an XMl file?  Please i need some help!! :)

Here's an example of my newbie code:

[code]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, xmldom, XMLIntf, StdCtrls, msxmldom, XMLDoc, stages;


type
  TForm1 = class(TForm)
    XMLDoc: TXMLDocument;
    BtnCreation: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    procedure BtnCreationClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BtnCreationClick(Sender: TObject);
var
  stage,stagiaires,stagiaire : IXMLNode;  //Noeuds de référence

begin
  memo1.Clear;
  XMLDoc.DocumentElement := XMLDoc.CreateElement('stages','');

  stage := XMLDoc.DocumentElement.AddChild('stage');

  stage.Attributes['nom'] := 'WORD 2000 Initiation';
  stage.Attributes['date'] := '14/06/2001';

  stagiaires := stage.AddChild('stagiaires');

  stagiaire := stagiaires.AddChild('stagiaire');
  stagiaire.Attributes['nom'] := 'MAGIC Jordan';
  stagiaire.Attributes['age'] := '35';

  stagiaire := stagiaires.AddChild('stagiaire');
  stagiaire.Attributes['nom'] := 'ESSONCHA Jean-Roland';
  stagiaire.Attributes['age'] := '38';


  stage := XMLDoc.DocumentElement.AddChild('stage');
  stage.Attributes['nom'] := 'SQL SERVER 7 Administration';
  stage.Attributes['date'] := '11/06/2001';

  memo1.Lines.Assign(XMLDoc.XML);
  XMLDoc.SaveToFile('stages.xml');

  end;


procedure TForm1.Button1Click(Sender: TObject);
var
  Element : IXMLStagesType;
  i: integer;
begin
  Element := GetStages(XMLDoc);
  for i := 0 to Element.stages.Count - 1
    do memo2.Lines.Add(Element.stagiaires[i].nom);
end;
end.
[/code]

I get errors while compiling
  [Error] Unit1.pas(79): Undeclared identifier: 'stages'
  [Fatal Error] Project1.dpr(6): Could not compile used unit 'Unit1.pas'

Thank you for any help.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21156543
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question