Что лучший способ состоит в том, чтобы сохранить набор Delphi в наборе данных?

Ваши три регулярных выражения, которые вам понадобятся для захвата упомянутых значений, будут такими,

Description="([^"]*)"
From="([^"]*)"
Thru="([^"]*)"

, которые вы можете динамически генерировать с помощью функции и повторно использовать ее для поиска значений для любого типа данных. Попробуйте эту демонстрацию кода Python,

import re

def getValue(str, key):
 m = re.search(key + '="([^"]*)"',str)
 if m:
  return m.group(1)

s = '''<Report Type="Final Report" SiteName="Get Dataset" Name="Get Metadata" Description="Get Metadata" From="2019-01-16 00:00" Thru="2019-01-16 23:59" obj_device="479999" locations="69,31,">
  <Objective Type="Availability">
    <Goal>99.99</Goal>
    <Actual>100.00</Actual>
    <Compliant>Yes</Compliant>
    <Errors>0</Errors>
    <Checks>2880</Checks>
    </Objective>
  <Objective Type="Uptime">
    <Goal/>
    <Actual/>
    <Compliant/>
    <Errors>0</Errors>
    <Checks>0</Checks>
  </Objective>'''

print('Description: ' + getValue(s,'Description'))
print('From: ' + getValue(s,'From'))
print('Thru: ' + getValue(s,'Thru'))

Prints,

Description: Get Metadata
From: 2019-01-16 00:00
Thru: 2019-01-16 23:59
6
задан Mason Wheeler 7 December 2008 в 13:45
поделиться

2 ответа

Вы могли использовать TBytesField или TBlobField

ClientDataSet1MySet: TBytesField, Size=32

var
  MySet: set of Byte;
  Bytes: array of Byte;
begin
  MySet := [1, 2, 4, 8, 16];

  // Write
  Assert(ClientDataSet1MySet.DataSize >= SizeOf(MySet), 'Data field is too small');

  SetLength(Bytes, ClientDataSet1MySet.DataSize);
  Move(MySet, Bytes[0], SizeOf(MySet));
  ClientDataSet1.Edit;
  ClientDataSet1MySet.SetData(@Bytes[0]);
  ClientDataSet1.Post;

  // Read
  SetLength(Bytes, ClientDataSet1MySet.DataSize);
  if ClientDataSet1MySet.GetData(@Bytes[0]) then
    Move(Bytes[0], MySet, SizeOf(MySet))
  else
    MySet := []; // NULL
end;
14
ответ дан 8 December 2019 в 14:48
поделиться

Можно преобразовать их в Байт, как это:

var
  States : TUpdateStatusSet; // Can be any set, I took this one from DB.pas unit
  SetAsAInteger: Integer;
  dbs: Pointer; // Here's the trick
begin
  States := [usModified, usInserted]; // Putting some content in that set
  dbs := @States;
  SetAsAInteger := PByte(dbs)^;
  //Once you got it, SetAsAInteger is just another ordinary integer variable.
  //Use it the way you like.
end;

Восстановиться отовсюду:

var
  MSG: string;
  Inserted, Modified: string;
  States: TUpdateStatusSet;
  MySet: Byte;

begin
  while not ClientDataSet.Eof do
  begin
    //That's the part that interest us
    //Convert that integer you stored in the database or whatever 
    //place to a Byte and, in the sequence, to your set type.
    iSet := Byte(ClientDatasetMyIntegerField);// Sets are one byte, so they
                                              //  fit on a byte variable  
    States := TUpdateStatusSet(iSet);
    //Conversion finished, below is just interface stuff


    if usInserted in States then
      Inserted := 'Yes';
    if usModified in States then
      Modified := 'Yes';
    MSG := Format('Register Num: %d. Inserted: %s. Modified:%s',
                  [ClientDataSet.RecNo, Inserted, Alterted]);
    ShowMessage( MSG );
    ClientDataset.Next;
  end;

end;
2
ответ дан 8 December 2019 в 14:48
поделиться
Другие вопросы по тегам:

Похожие вопросы: