⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osgrideditor.pas

📁 企业进销存管理系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    function  FullColorName(colorValue : String) : String;

    // Get Sample Grid Property functions
    function GetGridMode : TtsGridMode;
    function GetGridFont : TFont;
    function GetGridHeadingFont : TFont;
    function GetGridHeadingColor : TColor;
    function GetGridColor : TColor;
    //function GetGridDisplayColnr(iCol : Integer) : Integer;
    function GetGridDataColnr(iDisplayCol : Integer) : Integer;
    function GetGridCol(iCol : Integer) : TtsCol;
    function GetGridCurrentDataRow : Variant;
    function GetGridLeftCol : Integer;
    function GetGridFixedColCount : Integer;
    function GetGridCols : Integer;
    function GetGridSelectedCols : TtsSelection;
    function GetGridRows : Integer;
    function GetGridDefaultColWidth : Integer;
    function GetGridDefaultRowHeight : Integer;

    // Mask routines
    procedure LoadSystemMasks;
    function  IndexOfMask(sName : String) : Integer;
    procedure AppendCustomMasks;
    procedure AppendTtsMaskMasks;
    function  AddMaskEntry(sName, sPicture : String; bSystem : Boolean) : TosMaskEntry;
    function  AddMask(theMask : TosMaskEntry) : Boolean;
    procedure DefineNewMask;
    procedure EditMask(anEntry : TosMaskEntry);
    procedure SetMask;
    function  SourceMaskDefs : TtsMaskDefs;
    procedure PostionOnMaskName;
    procedure AdjustMaskCombo(sName : String);
  public
    { Public declarations }

    property  SelectedRow : Integer read FSelectedRow write SetSelectedRow;
    property  SelectedCol : Integer read FSelectedCol write SetSelectedCol;
    property  SelectedColProperty : Integer read FSelectedColProperty write SetSelectedColProperty;
    property  SelectedtsCol : TtsCol read GetSelectedtsCol;
    property  SelectedCombo : TtsCombo read GetSelectedCombo write SetSelectedCombo;
    property  SelectedRowProperty : Integer read FSelectedRowProperty write SetSelectedRowProperty;
    property  SelectedCellProperty : Integer read FSelectedCellProperty write SetSelectedCellProperty;
    property  DataBound : Boolean read GetDataBound;
    property  ColumnView : String read GetColumnView write SetColumnView;
    property  GridView : String read GetGridView write SetGridView;
    property  TargetGrid : TtsBaseGrid read FTargetGrid write SetTargetGrid;
  end;

function  BooleanToStr(Value : Boolean) : String;
procedure RunTimeEditor(aGrid : TtsBaseGrid);
procedure ApplyChanges;
procedure CustomAssign(tgtGrid, srcGrid : TtsBaseGrid);
procedure CustomColumnDbAssign(tgtGrid, srcGrid : TtsDbGrid);
procedure CustomColumnAssign(tgtGrid, srcGrid : TtsGrid);
procedure CustomRowAssign(tgtGrid, srcGrid : TtsGrid);
procedure CustomCellAssign(tgtGrid, srcGrid : TtsGrid);

{$IFNDEF TSVER_V5}
function GetPropValue(Instance: TObject; const PropName: string;
  PreferStrings: Boolean = True): Variant;
procedure SetPropValue(Instance: TObject; const PropName: string;
  const Value: Variant);
function PropType(Instance: TObject; const PropName: string): TTypeKind;
function GetEnumProp(Instance: TObject; const PropName: string): string;
function GetEnumProp2(Instance: TObject; PropInfo: PPropInfo): string;
function PropertyIsBoolean(Instance: TObject; const PropName: string) : Boolean;
{$ENDIF}

var
  fmOsGridEditor : TfmOsGridEditor;
  demoGrid : TtsBaseGrid;
  ControlProperties, BasicProperties, VCLProperties, EnumList, FieldNames, DataProperties : TStringList;
  ColControlProperties, ColBasicProperties, ColCustomProperties : TStringList;
  GridCustomProperties, GridModifiedProperties, ColModifiedProperties : TStringList;
  comboDataBookmarks, comboGridProperties : TStringList;
  lsDataSources, lsDateTimeDefs : TStringList;

  StartedFromDesigntime: Boolean = False;
  DesignActivatesFirstTime: Boolean = True;
  FirstActivate: Boolean = False;
  PrevLeft: Integer = 0;
  PrevTop: Integer = 0;
  PrevWidth: Integer = 0;
  PrevHeight: Integer = 0;
  PrevState: TWindowState = wsNormal;
  SourceGrid: TtsBaseGrid = nil;
  SaveResult : Boolean;
  srcFieldNames : TStringList;

implementation

uses {$IFDEF TSVER_V6} Types, {$ENDIF}
     duCustomGridProperties, duCustomColProperties, duDefineMask, duCustomMasks, duSpinOptions;

type
    TtsBaseGrid_ = class(TtsBaseGrid) end;
    TtsCustomGrid_ = class(TtsCustomGrid) end;
    TtsCustomDBGrid_ = class(TtsCustomDBGrid) end;

{TosGridEditor}

{$IFNDEF TSVER_V5}
function PropType(Instance: TObject; const PropName: string): TTypeKind;
var pInfo : PPropInfo;
begin
  pInfo := GetPropInfo(PTypeInfo(Instance.ClassInfo), PropName);
  Result := pInfo^.PropType^^.Kind;
end;

function GetPropValue(Instance: TObject; const PropName: string;
  PreferStrings: Boolean = True): Variant;
var pInfo : PPropInfo;
    sEnumText : String;
    iVal : Integer;
begin
  pInfo := GetPropInfo(PTypeInfo(Instance.ClassInfo), PropName);
  if pInfo = Nil then
     raise Exception.Create('Unable to locate property ' + PropName);
  if (PropType(Instance, PropName) = tkEnumeration) then
  begin
     iVal := GetOrdProp(Instance, pInfo);
     sEnumText := GetEnumName(pInfo^.PropType^, iVal);
     Result := sEnumText;
  end
  else if (PropType(Instance, PropName) = tkInteger) then
     Result := GetOrdProp(Instance, pInfo)
  else if (PropType(Instance, PropName) = tkClass) then
     Result := GetOrdProp(Instance, pInfo)
  else if (PropType(Instance, PropName) = tkLString) or
          (PropType(Instance, PropName) = tkWString) then
     Result := GetStrProp(Instance, pInfo)
  else
     Result := GetVariantProp(Instance, pInfo);
end;

procedure SetPropValue(Instance: TObject; const PropName: string;
  const Value: Variant);
var pInfo : PPropInfo;
    iEnumValue : Integer;
begin
  pInfo := GetPropInfo(PTypeInfo(Instance.ClassInfo), PropName);
  if pInfo = Nil then
     raise Exception.Create('Unable to locate property ' + PropName);
  if (PropType(Instance, PropName) = tkEnumeration) then
  begin
    iEnumValue := GetEnumValue(pInfo^.PropType^, Value);
    SetOrdProp(Instance, pInfo, iEnumValue)
  end
  else if (PropType(Instance, PropName) = tkInteger) then
     SetOrdProp(Instance, pInfo, Value)
  else if (PropType(Instance, PropName) = tkClass) then
     SetOrdProp(Instance, pInfo, Value)
  else if (PropType(Instance, PropName) = tkLString) or
          (PropType(Instance, PropName) = tkWString) then
     SetStrProp(Instance, pInfo, Value)
  else
     SetVariantProp(Instance, pInfo, Value);
end;

function GetEnumProp(Instance: TObject; const PropName: string): string;
var pInfo : PPropInfo;
begin
  pInfo := GetPropInfo(PTypeInfo(Instance.ClassInfo), PropName);
  if pInfo = Nil then
     raise Exception.Create('Unable to locate property ' + PropName);
  Result := GetEnumProp2(Instance, pInfo);
end;

function GetEnumProp2(Instance: TObject; PropInfo: PPropInfo): string;
begin
  Result := GetEnumName(PropInfo^.PropType^, GetOrdProp(Instance, PropInfo));
end;

function PropertyIsBoolean(Instance: TObject; const PropName: string) : Boolean;
var pInfo : PPropInfo;
begin
  pInfo := GetPropInfo(PTypeInfo(Instance.ClassInfo), PropName);
  if pInfo = Nil then
     raise Exception.Create('Unable to locate property ' + PropName);
  Result := (pInfo^.PropType^^.Name = 'Boolean');
end;

{$ENDIF}

{$IFNDEF rtTest}

procedure TosGridEditor.GetDateTimeDefName(const sValue : String);
var aDateTimeDef : TComponent;
begin
  aDateTimeDef := Designer.GetComponent(sValue);
  lsDateTimeDefs.AddObject(sValue, aDateTimeDef)
end;

procedure TosGridEditor.GetDatasourceName(const sValue : String);
var aDs : TComponent;
begin
  aDs := Designer.GetComponent(sValue);
  lsDataSources.AddObject(sValue, aDs)
end;

procedure TosGridEditor.ApplyDbColumns;
var i : Integer;
begin
  TtsDbGrid(SourceGrid).Cols := 0;
  TtsDbGrid(SourceGrid).Cols := fmOsGridEditor.sampleDbGrid.Cols;
  for i := 1 to fmOsGridEditor.sampleDbGrid.Cols do
    TtsDbGrid(SourceGrid).Col[i].Assign(fmOsGridEditor.sampleDbGrid.Col[i]);
end;

procedure TosGridEditor.Edit;
var i : integer;
    pInfo : PPropInfo;
    T: PTypeData;
begin
    SaveResult := False;
    StartedFromDesigntime := True;
    FirstActivate := True;
    srcFieldNames := TStringList.Create;
    lsDataSources := TStringList.Create;
    lsDateTimeDefs := TStringList.Create;
    Screen.Cursor := crHourglass;
    try
        SourceGrid := TtsBaseGrid(Component);
        fmOsGridEditor := TfmOsGridEditor.Create(Application);
    except
        Screen.Cursor := crDefault;
        fmOsGridEditor.Free;
        fmOsGridEditor := nil;
        raise;
    end;

    if SourceGrid is TtsDbGrid then
    begin
      {$IFNDEF TSVER_V5}
      pInfo := GetPropInfo(PTypeInfo(TtsDbGrid(SourceGrid).ClassInfo), 'DataSource');
      {$ELSE}
      pInfo := GetPropInfo(TtsDbGrid(SourceGrid), 'DataSource');
      {$ENDIF}
      T := GetTypeData(pInfo^.PropType^);
      Designer.GetComponentNames(T, GetDatasourceName);
    end;
    // Now Load DateTimeDefs
    {$IFNDEF TSVER_V5}
    pInfo := GetPropInfo(PTypeInfo(TtsDbGrid(SourceGrid).ClassInfo), 'DateTimeDef');
    {$ELSE}
    pInfo := GetPropInfo(TtsDbGrid(SourceGrid), 'DateTimeDef');
    {$ENDIF}
    T := GetTypeData(pInfo^.PropType^);
    Designer.GetComponentNames(T, GetDateTimeDefName);
          
    try
{$IFDEF TSVER_V6}
        fmOsGridEditor.Caption := TForm(Designer.Root).Name + '.' + Component.Name + ' - TopGrid Editor';
{$ELSE}
        fmOsGridEditor.Caption := Designer.Form.Name + '.' + Component.Name + ' - TopGrid Editor';
{$ENDIF}
        if DesignActivatesFirstTime then
        begin
            fmOsGridEditor.Left := Trunc((Screen.Width - fmOsGridEditor.Width)/2);
            fmOsGridEditor.Top  := Trunc((Screen.Height - fmOsGridEditor.Height)/2);

            PrevLeft := fmOsGridEditor.Left;
            PrevTop   := fmOsGridEditor.Top;
            PrevWidth := fmOsGridEditor.Width;
            PrevHeight := fmOsGridEditor.Height;

            DesignActivatesFirstTime := False;
        end
        else
        begin
            fmOsGridEditor.Left := PrevLeft;
            fmOsGridEditor.Top := PrevTop;
        end;

        if (SourceGrid is TtsDbGrid) and
           (TtsDbGrid(SourceGrid).DataSource <> Nil) then
        begin
          if TtsDbGrid(SourceGrid).DataSource.DataSet = Nil then
             raise Exception.Create('Unable to open TopGrid Designer - no dataset associated to TDatasource!');
           for i := 0 to TtsDbGrid(SourceGrid).DataSource.DataSet.FieldCount - 1 do
              srcFieldNames.Add(TtsDbGrid(SourceGrid).DataSource.DataSet.Fields.Fields[i].FieldName);
        end;
        
        //ShowMessage('ShowModal');
        fmOsGridEditor.ShowModal;
        if (not SaveResult) and
           (fmOsGridEditor.tbSave.Enabled) and
           (MessageDlg('You have unapplied changes - apply them?', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
           SaveResult := True;

        //ShowMessage('Exiting Editor');

        PrevState := fmOsGridEditor.WindowState;
        if PrevState = wsNormal then
        begin
            PrevLeft := fmOsGridEditor.Left;
            PrevTop := fmOsGridEditor.Top;
            PrevWidth := fmOsGridEditor.Width;
            PrevHeight := fmOsGridEditor.Height;
        end;

        if SaveResult then
        begin
            //ShowMessage('Assigning Grid Properties');
            ApplyChanges;
            Designer.Modified;
        end;
    finally
        srcFieldNames.Free;
        srcFieldNames := Nil;
        lsDateTimeDefs.Free;
        lsDateTimeDefs := Nil;
        lsDataSources.Free;
        lsDataSources := Nil;
        fmOsGridEditor.Free;
        fmOsGridEditor := Nil;

        Screen.Cursor := crDefault;
    end;
end;

function TosGridEditor.GetVerbCount: Integer;
begin
    result := 1;
end;

function TosGridEditor.GetVerb(Index: integer): string;
begin
    result := '&TopGrid Editor'
end;

procedure TosGridEditor.ExecuteVerb(Index: integer);
begin
    Edit;
end;
{$ENDIF}

{$R *.dfm}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -