RxFPC:TRxMemoryData.CopyStructure - add flag for create string/widestring fields. Idea from DmitrLoginov

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9373 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75 2024-06-28 20:36:57 +00:00
parent 0df033694b
commit 9de9860fb3

View File

@ -48,6 +48,8 @@ type
TMemoryRecord = class;
TLoadMode = (lmCopy, lmAppend);
TCompareRecords = function (Item1, Item2: TMemoryRecord): Integer of object;
TrxCopyStructureOption = (csoMapStringToWideString);
TrxCopyStructureOptions = set of TrxCopyStructureOption;
TRxMemoryData = class(TDataSet)
private
@ -169,7 +171,7 @@ type
CaseInsensitive: Boolean = True; Asc: array of boolean);
procedure EmptyTable;
procedure CloseOpen;
procedure CopyStructure(Source: TDataSet);
procedure CopyStructure(Source: TDataSet; AOptions:TrxCopyStructureOptions = []);
function LoadFromDataSet(Source: TDataSet; ARecordCount: Integer;
Mode: TLoadMode): Integer;
function SaveToDataSet(Dest: TDataSet; ARecordCount: Integer): Integer;
@ -1574,7 +1576,7 @@ begin
Open;
end;
procedure TRxMemoryData.CopyStructure(Source: TDataSet);
procedure TRxMemoryData.CopyStructure(Source: TDataSet; AOptions:TrxCopyStructureOptions = []);
procedure CheckDataTypes(FieldDefs: TFieldDefs);
var
@ -1600,8 +1602,13 @@ begin
// FieldDefs := Source.FieldDefs;
FieldDefs.Clear;
for i:=0 to Source.FieldDefs.Count-1 do
FieldDefs.Add(Source.FieldDefs[i].Name, Source.FieldDefs[i].DataType, Source.FieldDefs[i].Size, Source.FieldDefs[i].Required);
begin
if (Source.FieldDefs[i].DataType = ftString) and (csoMapStringToWideString in AOptions) then
FieldDefs.Add(Source.FieldDefs[i].Name, ftWideString, Source.FieldDefs[i].Size, Source.FieldDefs[i].Required)
else
FieldDefs.Add(Source.FieldDefs[i].Name, Source.FieldDefs[i].DataType, Source.FieldDefs[i].Size, Source.FieldDefs[i].Required);
end;
CheckDataTypes(FieldDefs);
CreateFields;
CopyFieldsFormat(Source);