📄 u_chmdesign.pas
字号:
unit U_ChmDesign;
interface
uses
EchmMain, Forms,
SysUtils, Classes, DBCtrls, DB;
type
TChmDesign = class(TComponent)
private
{ Private declarations }
FDsgnForm: TCustomForm;
FEchmForm: TEchmForm;
FActive: Boolean;
FDesign: boolean;
FUser: boolean;
FIsMHT: boolean;
{bin + DFM PAS存数据库}
FDataLink: TDataSourceLink;
FDataFieldName: string;
FPasFieldName: string;
FKeyfieldName: String;
FDataField: TField;
FPasField: TField;
FKeyField: TField;
FFrmName:string;
FUnitName:string;
function GetDataSource: TDataSource;
function GetPasFieldName: string;
procedure SetDataFieldName(const Value: string);
procedure SetKeyFieldName(const Value: string);
procedure SetDataSource(Value: TDataSource);
procedure SetPasFieldName(const Value: string);
procedure UpdatePasFields;
procedure UpdateDataFields;
procedure UpdateKeyFields;
{bin + DFM PAS存数据库}
procedure SetDsgnForm(const Value: TCustomForm);
protected
{ Protected declarations }
{bin + DFM PAS存数据库}
{ property DataLink: TDataSourceLink read FDataLink;}
{bin + DFM PAS存数据库}
property DsgnForm: TCustomForm read FDsgnForm write SetDsgnForm;
procedure Notification(AComponent: TComponent; Operation: TOperation);
override;
public
{ Public declarations }
procedure BeginDesign;
procedure EndDesign;
constructor Create(AOwner: TComponent); override;
{bin + DFM PAS存数据库}
property Field: TField read FDataField;
{bin + DFM PAS存数据库}
published
{bin + DFM PAS存数据库}
property DataField: string read FDataFieldName write SetDataFieldName;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property PasField: string read GetPasFieldName write SetPasFieldName;
property KeyField: string read FKeyfieldName write SetKeyFieldName;
property FrmName: string read FFrmName write FFrmName;
property UnitName: string read FUnitName write FUnitName;
{bin + DFM PAS存数据库}
property Design: boolean read FDesign write FDesign default True; //是否可以运行期设计
property User: boolean read FUser write FUser default True; //是否用户设计
property IsMHT: boolean read FIsMHT write FIsMHT default False; //是否MHT
{ Published declarations }
end;
implementation
{ TChmDesign }
constructor TChmDesign.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FActive := False;
FDesign :=True;
FUser :=True;
FIsMHT :=False;
if AOwner is TCustomForm then
DsgnForm := TCustomForm(AOwner);
{bin + DFM PAS存数据库}
FDataLink := TDataSourceLink.Create;
{bin + DFM PAS存数据库}
end;
procedure TChmDesign.BeginDesign;
var
I : Integer;
begin
if FDsgnForm = nil then
Exit;
for I := 0 to Owner.ComponentCount - 1 do
if (Owner.Components[I] is TChmDesign) and
(TChmDesign(Owner.Components[I]).FActive) then
Exit;
if FDesign = True then
begin
FEchmForm := TEchmForm.Create(Self);
FEchmForm.FDesign:=True; //调用方式
FEchmForm.FUser:= FUser;
FEchmForm.FIsMHT:=FIsMHT;
{bin //+运行状态设计单元文件的处理}
FEchmForm.FDataSource:=DataSource;
FEchmForm.FKeyField:=KeyField;
FEchmForm.FDataField:=DataField;
FEchmForm.FPasField:=PasField;
FEchmForm.FFrmName:=FFrmName;
FEchmForm.FUnitName:=FUnitName;
{bin //+运行状态设计单元文件的处理}
FActive := True;
FEchmForm.Show;
end;
end;
procedure TChmDesign.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FDsgnForm) then
FDsgnForm := nil;
end;
procedure TChmDesign.SetDsgnForm(const Value: TCustomForm);
begin
FDsgnForm := Value;
if Value <> nil then
begin
Value.FreeNotification(Self);
end;
end;
procedure TChmDesign.EndDesign;
begin
FEchmForm.HtmSaveToTable(TForm(FDsgnForm),DataSource,KeyField,DataField,PasField,FFrmName,FUnitName);
//存入数据库
FEchmForm.Free;
FActive := False;
end;
{bin + DFM PAS存数据库}
function TChmDesign.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
function TChmDesign.GetPasFieldName: string;
begin
Result := FPasFieldName;
end;
procedure TChmDesign.SetDataFieldName(const Value: string);
begin
if FDataFieldName <> Value then
begin
FDataFieldName := Value;
UpdateDataFields;
end;
end;
procedure TChmDesign.SetDataSource(Value: TDataSource);
begin
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
procedure TChmDesign.SetPasFieldName(const Value: string);
begin
if FPasFieldName <> Value then
begin
FPasFieldName := Value;
UpdatePasFields;
end;
end;
procedure TChmDesign.SetKeyFieldName(const Value: string);
begin
if FKeyfieldName <> Value then
begin
FKeyfieldName := Value;
UpdateKeyFields;
end;
end;
procedure TChmDesign.UpdatePasFields;
begin
FPasField := nil;
if FDataLink.Active and (FPasFieldName <> '') then
FPasField := GetFieldProperty(FDataLink.DataSet, Self, FPasFieldName);
end;
procedure TChmDesign.UpdateDataFields;
begin
FDataField := nil;
if FDataLink.Active and (FDataFieldName <> '') then
FDataField := GetFieldProperty(FDataLink.DataSet, Self, FDataFieldName);
end;
procedure TChmDesign.UpdateKeyFields;
begin
FKeyField := nil;
if FDataLink.Active and (FKeyfieldName <> '') then
FKeyField := GetFieldProperty(FDataLink.DataSet, Self, FKeyfieldName);
end;
{bin + DFM PAS存数据库}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -