TDBGridEh屬于哪個班級?我試過:
if (AForm.Components[i] IS TDBGridEh)
if (AForm.Components[i] IS TCustomDBGrid) or
if (AForm.Components[i] IS TCustomGrid) or
if (AForm.Components[i] IS TDBGrid) or
但我收到錯誤:未宣告的識別符號“***”
更新:
這是我對 的子元素TMainMenu和 的列的常用處理程式TDBGrid。我必須在這個通用處理程式中添加一些用于TDBGridEh.
有沒有一種方法,以對的子元素一個程序TDBGrid,TDBGridEh和TMainMenu?
procedure RightsOnSubElements(AForm: TForm; AComp: TComponent);
function FindFieldColumn(AComp: TComponent; const FieldName: String): TColumn;
var
i: Integer;
begin
Result := nil;
for i := 0 to (AComp as TDBGrid).Columns.Count - 1 do
if AnsiCompareText((AComp as TDBGrid).Columns[i].FieldName, FieldName) = 0 then
begin
Result := (AComp as TDBGrid).Columns[i];
Break;
end;
end;
var
Column : TColumn;
i: Integer;
begin
fMain.qSubElements.Close;
fMain.qSubElements.Parambyname('Form_Name').AsString := AForm.Name;
fMain.qSubElements.Parambyname('ROLE_ID').AsInteger := ROLE_ID;
fMain.qSubElements.Parambyname('name').AsString := AComp.Name;
fMain.qSubElements.Open;
if fMain.qSubElements.RecordCount > 0 then begin
while not fMain.qSubElements.Eof do begin
for i := 0 to AForm.ComponentCount - 1 do
if (AForm.Components[i] is TMenuItem) then begin
if UpperCase(AForm.Components[i].Name) = UpperCase(fMain.qSubElements.FieldByName('Sub_Name').AsString) then
begin
(AForm.Components[i] as TMenuItem).Visible := fmain.qSubElements.FieldByName('Visible').AsBoolean;
(AForm.Components[i] as TMenuItem).Enabled := fmain.qSubElements.FieldByName('Enabled').AsBoolean;
end;
end
else if (AForm.Components[i] is TDBGrid) then begin
if UpperCase(AForm.Components[i].Name) = UpperCase(fMain.qSubElements.FieldByName('Name').AsString) then
begin
Column := FindFieldColumn(AComp as TDBGrid, fMain.qSubElements.FieldByName('sub_name').AsString);
if Assigned(Column) then Column.Visible := fMain.qSubElements.FieldByName('Visible').AsBoolean;
end;
end;
fMain.qSubElements.Next;
end;
end;
end;
uj5u.com熱心網友回復:
什么是 DBGridEh 組件的父類?
根據 EhLib 的檔案:
TDBGridEh源自TCustomDBGridEh,- 源自
TCustomDBAxisGridEh, - 源自
TCustomGridEh, - 源自
TCustomControl
所以,當AForm.Components[i]是指一個TDBGridEh物體,它會檢測呈陽性TDBGridEh,但將測驗為陰性TCustomDBGrid,TCustomGrid和TDBGrid。
你已經知道如何區分TMainMenu從TDBGrid,那么什么是從區分阻止你TDBGridEh的TDBGrid?
procedure RightsOnSubElements(AForm: TForm; AComp: TComponent);
function FindFieldColumn(AComp: TDBGrid; const FieldName: String): TColumn;
var
i: Integer;
begin
for i := 0 to AComp.Columns.Count - 1 do begin
Result := AComp.Columns[i];
if SameText(Reslut.FieldName, FieldName) then
Exit;
end;
Result := nil;
end;
function FindFieldColumnEh(AComp: TDBGridEh; const FieldName: String): TColumnEh;
var
i: Integer;
begin
for i := 0 to AComp.Columns.Count - 1 do begin
Result := AComp.Columns[i];
if SameText(Result.FieldName, FieldName) then
Exit;
end;
Result := nil;
end;
var
Comp: TComponent;
Column : TColumn;
ColumnEh : TColumnEh;
i: Integer;
begin
fMain.qSubElements.Close;
fMain.qSubElements.Parambyname('Form_Name').AsString := AForm.Name;
fMain.qSubElements.Parambyname('ROLE_ID').AsInteger := ROLE_ID;
fMain.qSubElements.Parambyname('name').AsString := AComp.Name;
fMain.qSubElements.Open;
while not fMain.qSubElements.Eof do begin
Comp := AForm.FindComponent(fMain.qSubElements.FieldByName('Name').AsString);
if (Comp is TMenuItem) then begin
with TMenuItem(Comp) do begin
Visible := fmain.qSubElements.FieldByName('Visible').AsBoolean;
Enabled := fmain.qSubElements.FieldByName('Enabled').AsBoolean;
end;
end
else if (Comp is TDBGrid) then begin
Column := FindFieldColumn(TDBGrid(Comp), fMain.qSubElements.FieldByName('Sub_Name').AsString);
if Column <> nil then Column.Visible := fMain.qSubElements.FieldByName('Visible').AsBoolean;
end
else if (Comp is TDBGridEh) then begin
ColumnEh := FindFieldColumnEh(TDBGridEh(Comp), fMain.qSubElements.FieldByName('Sub_Name').AsString);
if Column <> nil then Column.Visible := fMain.qSubElements.FieldByName('Visible').AsBoolean;
end;
fMain.qSubElements.Next;
end;
end;
話雖如此,由于TDBGridEh具有與 類似的介面,但實際上并非源自TDBGrid,因此在 Delphi 2009 中,您可以為兩者撰寫通用代碼TDBGrid并TDBGridEh使用泛型,例如:
type
TInternalDBGridHelper<TDBGridType: class, TColumnType: class> = class
class function FindFieldColumn(AGrid: TDBGridType; const AFieldName: string): TColumnType;
class procedure SetFieldColumnVisible(AGrid: TDBGridType; const AFieldName: string; AVisible: Boolean);
end;
TInternalHelper_DBGrid = TInternalDBGridHelper<TDBGrid, TColumn>;
TInternalHelper_DBGridEh = TInternalDBGridHelper<TDBGridEh, TColumnEh>;
TDBGridHelper = class helper for TDBGrid
procedure SetFieldColumnVisible(const AFieldName: string; AVisible: Boolean);
end;
TDBGridEhHelper = class helper for TDBGridEh
procedure SetFieldColumnVisible(const AFieldName: string; AVisible: Boolean);
end;
class function TInternalDBGridHelper<TDBGridType, TColumnType>.FindFieldColumn(
AGrid: TDBGridType; const AFieldName: string): TColumnType;
var
I: Integer;
begin
for I := 0 to AGrid.Columns.Count-1 do
begin
Result := AGrid.Columns[I];
if SameText(Result.FieldName, AFieldName) then
Exit;
end;
Result := nil;
end;
class function TInternalDBGridHelper<TDBGridType, TColumnType>.SetFieldColumnVisible(
AGrid: TDBGridType; const AFieldName: string; AVisible: Boolean);
var
Column: TColumnType;
begin
Column := FindFieldColumn(AGrid, AFieldName);
if Assigned(Column) then Column.Visible := AVisible;
end;
procedure TDBGridHelper.SetFieldColumnVisible(const AFieldName: string; AVisible: Boolean);
begin
TInternalHelper_DBGrid.SetFieldColumnVisible(Self, AFieldName, AVisible);
end;
procedure TDBGridEhHelper.SetFieldColumnVisible(const AFieldName: string; AVisible: Boolean);
begin
TInternalHelper_DBGridEh.SetFieldColumnVisible(Self, AFieldName, AVisible);
end;
procedure RightsOnSubElements(AForm: TForm; AComp: TComponent);
var
Comp: TComponent;
i: Integer;
begin
fMain.qSubElements.Close;
fMain.qSubElements.Parambyname('Form_Name').AsString := AForm.Name;
fMain.qSubElements.Parambyname('ROLE_ID').AsInteger := ROLE_ID;
fMain.qSubElements.Parambyname('name').AsString := AComp.Name;
fMain.qSubElements.Open;
while not fMain.qSubElements.Eof do begin
Comp := AForm.FindComponent(fMain.qSubElements.FieldByName('Name').AsString);
if (Comp is TMenuItem) then begin
with TMenuItem(Comp) do begin
Visible := fmain.qSubElements.FieldByName('Visible').AsBoolean;
Enabled := fmain.qSubElements.FieldByName('Enabled').AsBoolean;
end;
end
else if (Comp is TDBGrid) then begin
TDBGrid(Comp).SetFieldColumnVisible(
fMain.qSubElements.FieldByName('Sub_Name').AsString,
fMain.qSubElements.FieldByName('Visible').AsBoolean);
end
else if (Comp is TDBGridEh) then begin
TDBGridEh(Comp).SetFieldColumnVisible(
fMain.qSubElements.FieldByName('Sub_Name').AsString,
fMain.qSubElements.FieldByName('Visible').AsBoolean);
end;
fMain.qSubElements.Next;
end;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/373132.html
標籤:德尔福
下一篇:Delphi:用陣列搜索字串
