I have a program for converting tab-delimited text to codebase foxpro
databases. One problem at the moment is that d4create doesn't work
with dynamic arrays of field or tag infos. This means I have to keep a
static array that is large enough to contain any potential database.
This leads to ugly code and bad dependencies. Is there any way to make
a dynamic datastructure that can be passed to d4create successfully
which is more scientific than just manually packing it into a block of
memory.
snippet of existing code starts here
Ok : Boolean;
idx : integer;
FieldInfo : Array [0..100] of Field4Info;
TagInfo : Array [0..100] of Tag4Info;
begin
if ( FldHdr.Unicode) then
begin
code4safety( CBEng, 0) ;
Code4Compatibility(CBEng, 30);
end
else
Code4Compatibility( CBEng, 26);
Code4ReadOnly(CBEng, 0);
Code4AccessMode(CBEng, OPEN4DENY_RW);
for idx := 0 to FldHdr.Count -1 do
begin
FieldInfo[ idx].Name := StrAlloc( length( FldHdr.Hdr( idx,
Ok).fName)+1);
StrPCopy( FieldInfo[ idx].name, FldHdr.Hdr( idx, Ok).FName);
FieldInfo[ idx].aType := FldHdr.Hdr( idx, Ok).fTypeRaw;
FieldInfo[ idx].Len := FldHdr.Hdr( idx, Ok).fWidth;
end; //for
//Always end a field array with NIL
idx := FldHdr.Count;
FieldInfo[ idx].name := Nil;
FieldInfo[ idx].aType := 0;
FieldInfo[ idx].len := 0;
FieldInfo[ idx].dec := 0;
//Now do the tags
for idx := 0 to Tags.count-1 do
begin
TagInfo[ idx].Name := StrAlloc( length( Tags.Tag(idx).tName)+1);
StrPCopy( TagInfo[ idx].name, Tags.Tag( idx).tName);
if ( length( Tags.Tag( idx).tExpression)>0) then
begin
TagInfo[ idx].expression := StrAlloc( length( Tags.Tag(
idx).tExpression)+1);
StrPCopy( TagInfo[ idx].expression, Tags.Tag( idx).tExpression);
end
else
begin
TagInfo[ idx].expression := StrAlloc( length( Tags.Tag(
idx).tName)+1);
StrPCopy( TagInfo[ idx].expression, Tags.Tag( idx).tName);
end; {else}


|