Solved

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

Posted on 2007-04-07
5
1,653 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
Magic Software info 18 138
Reconfigure Delphi Install? 2 61
WPF - Tooltips for ComboBox items 5 96
Adoquery sql  left join does not work 25 99
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 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