- This topic has 2 replies, 2 voices, and was last updated 3 years, 9 months ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
Home › Forums › kbmMemTable › Bug Report: CreateTableAs with lookup field and/or Calculated field
Environment:
O/S: Ubuntu linux 64bit
Compiler: fpc 3.2.0
Lazarus: 2.0.12
KbmMemTable: 7.92.00
There is a bug in function CreateTableAs with lookup and calculated field.
Here is a code to demonstrate the bug:
procedure TForm1.Button1Click(Sender: TObject);
var
MTable1,MTable2:TKbmMemTable;
Field : TField;
begin
MTable1 := TKbmMemTable.Create(NIL);
try
// Create data field
Field := TStringField.Create(MTable1);
Field.FieldName:=’KODE’;
Field.DataSet := MTable1;
Field.FieldKind:=fkData;// Create lookup field
Field := TFloatField.Create(MTable1);
Field.FieldName:=’LOOKUP_FIELD’;
Field.DataSet := MTable1;
Field.FieldKind:=fkLookup;// Create calculated field
Field := TFloatField.Create(MTable1);
Field.FieldName:=’CALC_FIELD’;
Field.DataSet := MTable1;
Field.FieldKind:=fkCalculated;// Create MTable2
MTable2 := TKbmMemTable.Create(NIL);
try
MTable2.CreateTableAs(MTable1,[mtcpoCalculated,mtcpoLookup]);
MTable2.CreateTable;
finally
MTable2.Free;
end;
finally
MTable1.Free;
end;
end;
Fortunately, it’s easy to fix. The bug actually is in function CopyFieldDefs. When copying the field def you forgot to copy the InternalCalcField field. Here is my patch:
— kbmMemTable.pas.patched1 2022-01-27 07:30:00.520126179 +0700
+++ kbmMemTable.pas 2022-02-27 23:37:14.262662414 +0700
@@ -5195,6 +5195,13 @@
fd.Size:=Source[i].Size;
fd.Required:=Source[i].Required;
fd.Precision:=Source[i].Precision;
+
+ {***********
+ PATCHED BY BAMBANG 27 Feb 2022
+ without this Calculated and Lookup field will
+ be flag as data field.
+ ************}
+ fd.InternalCalcField:=Source[i].InternalCalcField;
{$IFNDEF FPC}
if AForAttach then
fd.FieldNo:=Source[i].FieldNo;
Hope this fix is included in the new version.
Hello Kim,
I hope you didn’t miss this.
Thank you.
Hi,
The fix will be included in upcoming release.
/Kim