L
lewa
Unregistered / Unconfirmed
GUEST, unregistred user!
初写控件,想设计个从FlatSpinEdit继承的与数据相关控件(不想从TEDit类下继承),现
在问题是可以当值变了,相关字段总不能更新,请各位高手help下。程序如下:
type
TDBFlatSpinEditFloat = class(TFlatSpinEditFloat)
private
FDataLink : TFieldDataLink;
function GetField : TField;
function GetDataField : string;
procedure SetDataField(const Value: string);
function GetDataSource : TDataSource ;
procedure SetDataSource(Value : TDataSource);
procedure CMExit(var Message:TCMExit);message CM_Exit;
procedure SetValue(Value: Extended);
protected
procedure DataChange(sender : TObject);
procedure UpdateData(sender : TObject);
procedure ActiveChange(sender : TObject);
procedure UpClick(Sender: TObject);
procedure DownClick(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Field: TField read GetField;
published
property DataField: string read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
end;
procedure Register;
implementation
function TDBFlatSpinEditFloat.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TDBFlatSpinEditFloat.SetDataSource(Value: TDataSource);
begin
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
Enabled := FDataLink.Active and (FDataLink.Field <> nil) and
not FDataLink.Field.ReadOnly ;
end;
function TDBFlatSpinEditFloat.GetField: TField;
begin
Result := FDataLink.Field;
end;
function TDBFlatSpinEditFloat.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
procedure TDBFlatSpinEditFloat.SetDataField(const Value: string);
begin
FDataLink.FieldName := Value;
end;
constructor TDBFlatSpinEditFloat.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
//FDataLink.OnEditingChange := EditingChange;
FDataLink.OnUpdateData := UpdateData;
FDataLink.OnActiveChange := ActiveChange;
// Enabled := false;
end;
destructor TDBFlatSpinEditFloat.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TDBFlatSpinEditFloat.DataChange(sender : TObject);
begin
if (FDataLink.Field <> nil) and
((FDataLink.Field is TFloatField) or (FDataLink.Field is TCurrencyField)) then
value := FDataLink.Field.AsFloat
else
value := 0.00;
end;
procedure TDBFlatSpinEditFloat.UpdateData(sender : TObject);
begin
// if (FDataLink.Field <> nil) and
// ((FDataLink.Field is TFloatField) or (FDataLink.Field is TCurrencyField)) then
FDataLink.Field.AsFloat := value ;
end;
procedure TDBFlatSpinEditFloat.ActiveChange(sender : TObject);
begin
Enabled := FDataLink.Active and (FDataLink.Field <> nil);
end;
procedure TDBFlatSpinEditFloat.CMExit(var Message:TCMExit);
begin
try
FDataLink.UpdateRecord;
except
SelectAll;
SetFocus;
raise;
end;
inherited;
end;
procedure TDBFlatSpinEditFloat.SetValue(Value: Extended);
begin
FDataLink.Edit ; //使数据进入编写状态
inherited; //调用父类方法处理事件
FDataLink.Modified ;//更新了,通知系统
end;
procedure TDBFlatSpinEditFloat.UpClick(Sender: TObject);
begin
FDataLink.Edit ; //使数据进入编写状态
inherited; //调用父类方法处理事件
FDataLink.Modified ;//更新了,通知系统
end;
procedure TDBFlatSpinEditFloat.DownClick(Sender: TObject);
begin
FDataLink.Edit ; //使数据进入编写状态
inherited; //调用父类方法处理事件
FDataLink.Edit ;//更新了,通知系统
end;
procedure Register;
begin
RegisterComponents('DBFlatStyle', [TDBFlatSpinEditFloat]);
end;
end.
在问题是可以当值变了,相关字段总不能更新,请各位高手help下。程序如下:
type
TDBFlatSpinEditFloat = class(TFlatSpinEditFloat)
private
FDataLink : TFieldDataLink;
function GetField : TField;
function GetDataField : string;
procedure SetDataField(const Value: string);
function GetDataSource : TDataSource ;
procedure SetDataSource(Value : TDataSource);
procedure CMExit(var Message:TCMExit);message CM_Exit;
procedure SetValue(Value: Extended);
protected
procedure DataChange(sender : TObject);
procedure UpdateData(sender : TObject);
procedure ActiveChange(sender : TObject);
procedure UpClick(Sender: TObject);
procedure DownClick(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Field: TField read GetField;
published
property DataField: string read GetDataField write SetDataField;
property DataSource: TDataSource read GetDataSource write SetDataSource;
end;
procedure Register;
implementation
function TDBFlatSpinEditFloat.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TDBFlatSpinEditFloat.SetDataSource(Value: TDataSource);
begin
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
Enabled := FDataLink.Active and (FDataLink.Field <> nil) and
not FDataLink.Field.ReadOnly ;
end;
function TDBFlatSpinEditFloat.GetField: TField;
begin
Result := FDataLink.Field;
end;
function TDBFlatSpinEditFloat.GetDataField: string;
begin
Result := FDataLink.FieldName;
end;
procedure TDBFlatSpinEditFloat.SetDataField(const Value: string);
begin
FDataLink.FieldName := Value;
end;
constructor TDBFlatSpinEditFloat.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
//FDataLink.OnEditingChange := EditingChange;
FDataLink.OnUpdateData := UpdateData;
FDataLink.OnActiveChange := ActiveChange;
// Enabled := false;
end;
destructor TDBFlatSpinEditFloat.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TDBFlatSpinEditFloat.DataChange(sender : TObject);
begin
if (FDataLink.Field <> nil) and
((FDataLink.Field is TFloatField) or (FDataLink.Field is TCurrencyField)) then
value := FDataLink.Field.AsFloat
else
value := 0.00;
end;
procedure TDBFlatSpinEditFloat.UpdateData(sender : TObject);
begin
// if (FDataLink.Field <> nil) and
// ((FDataLink.Field is TFloatField) or (FDataLink.Field is TCurrencyField)) then
FDataLink.Field.AsFloat := value ;
end;
procedure TDBFlatSpinEditFloat.ActiveChange(sender : TObject);
begin
Enabled := FDataLink.Active and (FDataLink.Field <> nil);
end;
procedure TDBFlatSpinEditFloat.CMExit(var Message:TCMExit);
begin
try
FDataLink.UpdateRecord;
except
SelectAll;
SetFocus;
raise;
end;
inherited;
end;
procedure TDBFlatSpinEditFloat.SetValue(Value: Extended);
begin
FDataLink.Edit ; //使数据进入编写状态
inherited; //调用父类方法处理事件
FDataLink.Modified ;//更新了,通知系统
end;
procedure TDBFlatSpinEditFloat.UpClick(Sender: TObject);
begin
FDataLink.Edit ; //使数据进入编写状态
inherited; //调用父类方法处理事件
FDataLink.Modified ;//更新了,通知系统
end;
procedure TDBFlatSpinEditFloat.DownClick(Sender: TObject);
begin
FDataLink.Edit ; //使数据进入编写状态
inherited; //调用父类方法处理事件
FDataLink.Edit ;//更新了,通知系统
end;
procedure Register;
begin
RegisterComponents('DBFlatStyle', [TDBFlatSpinEditFloat]);
end;
end.