Subject | External file native format. |
---|---|
Author | Woody |
Post date | 2011-03-14T18:30:09Z |
I admit I am not as up to speed regarding external files for FB because I've
never had the need, until now.
I've been working with the class template laid out by Henrique Netzka
(excellent start using his article, thanks) that I found on the
FirebirdSQL.org site. One piece of unfinished code is the saving of time
stamp data. It saves the date portion fine but is not finished to include
the time portion. Can anyone help me by completing the method? I have only
included the particular method below but can post everything if needed. It's
not that large a class after all.
I have renamed his TIBRecord class to TTMWFBRecord for my own purposes.
Below is a short version of his class because I only need integer and
time/date storage at the moment. If anyone has a different but completed
class definition, regardless of who made it, I would also be interested. I
haven't cemented anything in code yet, just testing at the moment. I use
Delphi so all code must be in Pascal, sorry. :-(
TTMWFBRecord = class
private
fLine: array [1..4096] of char;
fPos: integer;
function GetLine: string;
protected
procedure CheckOffset(ANextSize: integer; AChar: boolean = false);
public
constructor Create;
procedure AppendInteger(Value: integer);
procedure AppendDateTime(Value: TDateTime);
procedure Reset;
property Line: string read GetLine;
property Pos: integer read FPos write FPos;
end;
{
This procedure is the one that I need help with. As you can see, the
date portion is saved to the buffer but the time portion is zeroed out.
}
procedure TTMWFBRecord.AppendDateTime(Value: TDateTime);
var
BaseDate: TDateTime;
dAux: integer;
buf: array[1..8] of byte;
begin
CheckOffset(8);
BaseDate := -15018;
// here the date is truncated losing the time portion..
dAux := Trunc(Value - BaseDate);
buf[1] := dAux and 255;
buf[2] := ((dAux and (255 SHL 8)) SHR 8);
buf[3] := ((dAux and (255 SHL 16)) SHR 16);
buf[4] := ((dAux and (255 SHL 24)) SHR 24);
{ I assume that I need something here besides zeroes to save the time
??? }
ZeroMemory(@buf[5], 4);
CopyMemory(@FLine[FPos], @buf, 8);
Inc(fPos, 8);
end;
TIA
Woody (TMW)
never had the need, until now.
I've been working with the class template laid out by Henrique Netzka
(excellent start using his article, thanks) that I found on the
FirebirdSQL.org site. One piece of unfinished code is the saving of time
stamp data. It saves the date portion fine but is not finished to include
the time portion. Can anyone help me by completing the method? I have only
included the particular method below but can post everything if needed. It's
not that large a class after all.
I have renamed his TIBRecord class to TTMWFBRecord for my own purposes.
Below is a short version of his class because I only need integer and
time/date storage at the moment. If anyone has a different but completed
class definition, regardless of who made it, I would also be interested. I
haven't cemented anything in code yet, just testing at the moment. I use
Delphi so all code must be in Pascal, sorry. :-(
TTMWFBRecord = class
private
fLine: array [1..4096] of char;
fPos: integer;
function GetLine: string;
protected
procedure CheckOffset(ANextSize: integer; AChar: boolean = false);
public
constructor Create;
procedure AppendInteger(Value: integer);
procedure AppendDateTime(Value: TDateTime);
procedure Reset;
property Line: string read GetLine;
property Pos: integer read FPos write FPos;
end;
{
This procedure is the one that I need help with. As you can see, the
date portion is saved to the buffer but the time portion is zeroed out.
}
procedure TTMWFBRecord.AppendDateTime(Value: TDateTime);
var
BaseDate: TDateTime;
dAux: integer;
buf: array[1..8] of byte;
begin
CheckOffset(8);
BaseDate := -15018;
// here the date is truncated losing the time portion..
dAux := Trunc(Value - BaseDate);
buf[1] := dAux and 255;
buf[2] := ((dAux and (255 SHL 8)) SHR 8);
buf[3] := ((dAux and (255 SHL 16)) SHR 16);
buf[4] := ((dAux and (255 SHL 24)) SHR 24);
{ I assume that I need something here besides zeroes to save the time
??? }
ZeroMemory(@buf[5], 4);
CopyMemory(@FLine[FPos], @buf, 8);
Inc(fPos, 8);
end;
TIA
Woody (TMW)