Ignore:
Timestamp:
Jun 13, 2011, 2:35:01 PM (13 years ago)
Author:
george
Message:
  • Fixed: Loading content of RelationMany sublist in item view.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UItemView.pas

    r16 r17  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ExtCtrls, ComCtrls, USqlDatabase, USystem;
     9  ExtCtrls, ComCtrls, USqlDatabase, USystem, SpecializedList;
    1010
    1111type
     
    2828    procedure FormCreate(Sender: TObject);
    2929    procedure FormDestroy(Sender: TObject);
     30    procedure FormResize(Sender: TObject);
    3031    procedure FormShow(Sender: TObject);
     32    procedure ListView1Data(Sender: TObject; Item: TListItem);
     33    procedure ListView1Resize(Sender: TObject);
     34    procedure TabControl1Change(Sender: TObject);
    3135  private
     36    SubListObject: TChronisObject;
     37    TabObjectList: TListInteger;
     38    TabDataTypeList: TListObject;
     39    procedure LoadSubList;
    3240    { private declarations }
    3341  public
     
    5664procedure TItemViewForm.FormCreate(Sender: TObject);
    5765begin
     66  SubListObject := TChronisObject.Create;
     67  SubListObject.Base := Core.System;
    5868  Report := TReport.Create;
    5969  Report.Base := Core.System;
     70  TabObjectList := TListInteger.Create;
     71  TabDataTypeList := TListObject.Create;
     72  TabDataTypeList.OwnsObjects := False;
     73  TabControl1.Tabs.Clear;
    6074end;
    6175
    6276procedure TItemViewForm.FormDestroy(Sender: TObject);
    6377begin
     78  SubListObject.Free;
    6479  Report.Free;
     80  TabObjectList.Free;
     81  TabDataTypeList.Free;
     82end;
     83
     84procedure TItemViewForm.FormResize(Sender: TObject);
     85begin
     86  ListView1Resize(Self);
    6587end;
    6688
     
    85107  MainForm.PersistentForm.Load(Self);
    86108  BuildControls;
     109  LoadSubList;
     110end;
     111
     112procedure TItemViewForm.ListView1Data(Sender: TObject; Item: TListItem);
     113var
     114  I: Integer;
     115begin
     116  if Item.Index < Report.Count then
     117  with TReportLine(Report[Item.Index]) do begin
     118    Item.Caption := Items[0];
     119    for I := 1 to Items.Count - 1 do
     120    if not TReportColumn(Report.Columns[I]).VirtualItem then
     121      Item.SubItems.Add(Items[I]);
     122  end;
    87123end;
    88124
     
    105141
    106142  TabControl1.Tabs.Clear;
     143  TabObjectList.Clear;
     144  TabDataTypeList.Clear;
    107145  // Load column names
    108146
     
    110148  for I := 0 to Report.Columns.Count - 1 do begin
    111149    DataType := TReportColumn(Report.Columns[I]).CustomType;
     150    DataType.LoadDef(TReportColumn(Report.Columns[I]).CustomType.CustomType);
    112151  if DataType is TDataTypeRelationMany then begin
    113152    TabControl1.Tabs.Add(TReportColumn(Report.Columns[I]).Caption);
     153    TabDataTypeList.Add(DataType);
     154    TabObjectList.Add(MainForm.SelectedItem);
    114155  end else begin
    115156    NewControl := TLabel.Create(PanelControls);
     
    132173end;
    133174
     175procedure TItemViewForm.LoadSubList;
     176var
     177  NewColumn: TListColumn;
     178  I: Integer;
     179begin
     180  //SelectedObjectId := 0;
     181  if (TabControl1.TabIndex >= 0) and (TabControl1.TabIndex < TabControl1.Tabs.Count) then
     182  with ListView1 do
     183  with TDataTypeRelationMany(TabDataTypeList[TabControl1.TabIndex]) do begin
     184    Visible := True;
     185    SubListObject.Load(ObjectId);
     186    Report.Load(SubListObject, '`' + PropertyName + '`=' + IntToStr(TabObjectList[TabControl1.TabIndex]));
     187
     188    Columns.Clear;
     189    for I := 0 to Report.Columns.Count - 1 do
     190    if not TReportColumn(Report.Columns[I]).VirtualItem then begin
     191      NewColumn := Columns.Add;
     192      NewColumn.Caption := TReportColumn(Report.Columns[I]).Caption;
     193    end;
     194    Items.Count := Report.Count;
     195    Refresh;
     196  end;
     197  ListView1Resize(Self);
     198end;
     199
     200procedure TItemViewForm.ListView1Resize(Sender: TObject);
     201var
     202  I: Integer;
     203begin
     204  for I := 0 to ListView1.Columns.Count - 1 do
     205    ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
     206end;
     207
     208procedure TItemViewForm.TabControl1Change(Sender: TObject);
     209begin
     210  LoadSubList;
     211end;
     212
     213
    134214end.
    135215
Note: See TracChangeset for help on using the changeset viewer.