Changeset 9 for trunk/Forms/UItemAdd.pas


Ignore:
Timestamp:
Dec 26, 2010, 8:12:59 PM (14 years ago)
Author:
george
Message:
  • Modified: Non-visual functions moved to USystem unit.
  • Modified: Loading of object, properties and values rebuilded to general structures.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22Config.xml
        33chronis
         4heaptrclog.trc
  • trunk/Forms/UItemAdd.pas

    r7 r9  
    11unit UItemAdd;
    22
    3 {$mode objfpc}{$H+}
     3{$mode Delphi}{$H+}
    44
    55interface
     
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9    StdCtrls, Spin, EditBtn, MaskEdit, USqlDatabase;
     9   StdCtrls, Spin, EditBtn, MaskEdit, USqlDatabase, USystem;
    1010
    1111type
     
    2020    procedure ButtonSaveClick(Sender: TObject);
    2121    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     22    procedure FormCreate(Sender: TObject);
     23    procedure FormDestroy(Sender: TObject);
    2224    procedure FormShow(Sender: TObject);
    2325  private
     
    2527    { private declarations }
    2628  public
    27     { public declarations }
     29    Report: TReport;
    2830  end;
    2931
     
    5658end;
    5759
     60procedure TItemAddForm.FormCreate(Sender: TObject);
     61begin
     62  Report := TReport.Create;
     63  Report.Base := MainForm.System;
     64end;
     65
     66procedure TItemAddForm.FormDestroy(Sender: TObject);
     67begin
     68  Report.Free;
     69end;
     70
    5871procedure TItemAddForm.FormShow(Sender: TObject);
    5972begin
     
    6477procedure TItemAddForm.BuildControls;
    6578var
    66   Properties: TDbRows;
    67   Values: TDbRows;
    6879  NewControl: TControl;
    6980  LastTop: Integer;
    7081  I: Integer;
    7182  Column: Integer;
    72   ObjectInfo: TDbRows;
    7383  ValueType: Integer;
    7484const
     
    7787  LastTop := 8;
    7888  Column := 0;
    79   try
    80   ObjectInfo := TDbRows.Create;
    81   MainForm.Database.Query(ObjectInfo, 'SELECT * FROM `Object` WHERE `Id`=' + IntToStr(MainForm.SelectedObject));
    82   if ObjectInfo.Count = 1 then begin
    8389
    84     for I := Panel1.ControlCount - 1 downto 0 do
    85       Panel1.Controls[I].Free;
     90  for I := Panel1.ControlCount - 1 downto 0 do
     91    Panel1.Controls[I].Free;
    8692
    87     // Load column names
    88     try
    89     Properties := TDbRows.Create;
    90     MainForm.Database.Query(Properties, 'SELECT * FROM `Property` WHERE `Object`=' +
    91       IntToStr(MainForm.SelectedObject));
    92     for I := 0 to Properties.Count - 1 do begin
     93  Report.Load(MainForm.SelectedObject, MainForm.SelectedObject.PrimaryKey + ' = ' +
     94    IntToStr(MainForm.SelectedItem));
     95
     96  // Load column names
     97    for I := 0 to Report.Columns.Count - 1 do
     98    if TReportColumn(Report.Columns[I]).ColumnName <> 'Id' then begin
    9399      NewControl := TLabel.Create(Panel1);
    94100      NewControl.Parent := Panel1;
    95101      NewControl.Top := LastTop;
    96102      NewControl.Left := Column * Width div ColumnCount + 10;
    97       TLabel(NewControl).Caption := Properties[I].Values['Name'] + ':';
     103      TLabel(NewControl).Caption := TReportColumn(Report.Columns[I]).Caption + ':';
    98104
    99       ValueType := StrToInt(Properties[I].Values['Type']);
     105      ValueType := TReportColumn(Report.Columns[I]).TypeId;
    100106      if ValueType = Integer(vtInteger) then begin
    101107        NewControl := TSpinEdit.Create(Panel1);
     
    149155      if Column = 0 then LastTop := LastTop + NewControl.Height + 4;
    150156    end;
    151 
    152     finally
    153       Properties.Free;
    154     end;
    155   end else ShowMessage(SObjectNotFound);
    156   finally
    157     ObjectInfo.Free;
    158   end;
    159157end;
    160158
Note: See TracChangeset for help on using the changeset viewer.