Solved

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

Posted on 2007-04-07
5
1,639 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 77
array6 challenfge 6 81
Open a URL with Internet Explorer in a new tab (not a new window) 1 71
Graphics32 under Delphi 10.1 Berlin 2 36
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 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

16 Experts available now in Live!

Get 1:1 Help Now