Ignore:
Timestamp:
Jan 18, 2015, 5:25:37 PM (10 years ago)
Author:
chronos
Message:
  • Added: Support for editing String and DateTime value types in record edit form.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33MyData.lps
        44data.xml
         5Config.xml
  • trunk/Forms/UFormRecords.pas

    r2 r3  
    3131    procedure ARemoveExecute(Sender: TObject);
    3232    procedure FormShow(Sender: TObject);
     33    procedure ListView1Data(Sender: TObject; Item: TListItem);
    3334    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
    3435      Selected: Boolean);
     
    4647implementation
    4748
     49uses
     50  UFormRecord;
     51
    4852{$R *.lfm}
    4953
     
    5357begin
    5458  Caption := 'Table - ' + Table.Name;
    55   UpdateInterface;
     59  ReloadList;
     60end;
     61
     62procedure TFormRecords.ListView1Data(Sender: TObject; Item: TListItem);
     63var
     64  I: Integer;
     65begin
     66  if (Item.Index >= 0) and (Item.Index < Table.Records.Count) then
     67  with TRecord(Table.Records[Item.Index]) do begin
     68    for I := 0 to Table.Fields.Count - 1 do begin
     69      if I = 0 then Item.Caption := TValue(Values[0]).GetString
     70        else Item.SubItems.Add(TValue(Values[I]).GetString);
     71    end;
     72    Item.Data := Table.Records[Item.Index];
     73  end
    5674end;
    5775
     
    6482procedure TFormRecords.AModifyExecute(Sender: TObject);
    6583begin
    66 
     84  if Assigned(ListView1.Selected) then begin
     85    FormRecord.Table := Table;
     86    FormRecord.Load(TRecord(ListView1.Selected.Data));
     87    if FormRecord.ShowModal = mrOk then begin
     88      FormRecord.Save(TRecord(ListView1.Selected.Data));
     89      ReloadList;
     90    end;
     91  end;
    6792end;
    6893
    6994procedure TFormRecords.ARemoveExecute(Sender: TObject);
    7095begin
    71 
     96  if Assigned(ListView1.Selected) then begin
     97    Table.Records.Remove(ListView1.Selected.Data);
     98    ReloadList;
     99  end;
    72100end;
    73101
    74102procedure TFormRecords.AAddExecute(Sender: TObject);
     103var
     104  NewRecord: TRecord;
     105  ValueClass: TValueClass;
     106  I: Integer;
     107  NewValue: TValue;
    75108begin
     109  NewRecord := TRecord.Create;
     110  NewRecord.Parent := Table;
     111  NewRecord.Values.Count := Table.Fields.Count;
     112  for I := 0 to Table.Fields.Count - 1 do begin
     113    ValueClass := TField(Table.Fields[I]).GetValueClass;
     114    NewValue := ValueClass.Create;
     115    NewRecord.Values[I] := NewValue;
     116  end;
    76117
     118  FormRecord.Table := Table;
     119  FormRecord.Load(NewRecord);
     120  if FormRecord.ShowModal = mrOk then begin
     121    FormRecord.Save(NewRecord);
     122    Table.Records.Add(NewRecord);
     123    ReloadList;
     124  end else NewRecord.Free;
    77125end;
    78126
     
    84132
    85133procedure TFormRecords.ReloadList;
     134var
     135  I: Integer;
     136  NewColumn: TListColumn;
    86137begin
     138  ListView1.Columns.Clear;
     139  for I := 0 to Table.Fields.Count - 1 do begin
     140    NewColumn := ListView1.Columns.Add;
     141    NewColumn.Caption := TField(Table.Fields[I]).TextBefore;
     142    NewColumn.Width := 200;
     143  end;
     144
    87145  ListView1.Items.Count := Table.Records.Count;
    88146  ListView1.Repaint;
Note: See TracChangeset for help on using the changeset viewer.