Board index » delphi » copy from a binary untyped file to Paradox

copy from a binary untyped file to Paradox

Hello,

I want to copy from a 'binary untyped file' (='mysourcefile') to a
Paradox
table(='mytargetfile').
the design of 'mysourcefile' is as follows:
- 1st field: 'a1'       name of field 'n client' :            4 bytes
- 2nd field:'a2'        name of field 'invoice type' :  1 byte,

If i code as follows (hereafter), all is Ok *except something major*:
the size of my 'buf' var is not like expected :
- 'sizeof(buf)' = 8 bytes, instead of 4+1 bytes expected

My questions are:
1. how to define a 'buf' var. with the exact length of 'mysourcefile'
record?
2. If it is not the right way to copy 'mysourcefile' to
'mytargetfile', how should i do?
3. how to begin the reading of my 'mysourcefile' at the record n
1000 (example)?
4. how to condition the record's writing to my 'mytargetfile' to the
value of the first field (example: a1=10)?

Thank you very much for your help
Didier

here is my code:

type
    str = record
    a1 : longint;     {n client}
    a2 : string[0];   {invoice type}
        ...
    end;

procedure versparadox;

implementation

procedure versparadox;
var
buf : str;
f : file;
numread:integer;
begin
  assignfile(f, 'c:\mes documents\didier\lpe\amco\vttran98') ; //
define 'mysourcefile'
  reset(f,1) ;
  form1.Table1.open ;                                   // open 'mytargetfile'
  repeat
    form1.Table1.edit;
    fillchar(buf,sizeof(Buf),0);
    BlockRead(F, Buf, SizeOf(Buf), NumRead);
    if numread>0 then
    begin
    try
      with buf do
        form1.Table1.insertrecord([a1,a2, ...]);
      except on E:Edatabaseerror do
      begin
        showmessage(E.message);
        form1.Table1.cancel;
        form1.Table1.close;
        exit;
      end;
    end;
    end;
  until (NumRead = 0);
  CloseFile(F);
  form1.Table1.Close;
end;

 

Re:copy from a binary untyped file to Paradox


Hi Didier,
declare your str record structure as "packed":
Type
    str = PACKED record
    a1 : longint;     {n client}
    a2 : string[0];   {invoice type}
  end;

--
Roman
I...@rksolution.cz (please remove STOPSPAM. in header)
Delphi corner now open at my website http://www.rksolution.cz

Quote
Didier Cabal <106716.3...@compuserve.com> wrote in message

<01bdb0f9$d0e425c0$3f49e...@none.compuserve.com>...
Quote
> ..........
>the size of my 'buf' var is not like expected :
>- 'sizeof(buf)' = 8 bytes, instead of 4+1 bytes expected
> ........

Re:copy from a binary untyped file to Paradox


Hello Roman,
i would say two things: BRAVO and Thank you for your help
Didier

Roman Krejci <STOPSPAM.KRE...@MBOX.CESNET.CZ> a crit dans l'article
<6on923$9v...@forums.borland.com>...

Quote
> Hi Didier,
> declare your str record structure as "packed":

Other Threads