Solved

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

Posted on 2007-04-07
5
1,638 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
  • 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now