H
haha2003
Unregistered / Unconfirmed
GUEST, unregistred user!
我想開發一個數據控件.在開發的過程中遇到點問題一直沒法解決,我寫的這個控件在設計狀態下能正常工作(能返回datasource.dataset的值)而在編輯時會出錯,主要原因是我寫的這個控件的datasource能返回值,而dataset卻不能返回值.不知是什麼原因1.而我寫的程序的datasource連接的table已經連接到表並且已找開.那位能幫忙.我先謝了.我的QQ是:83328047
=================================================================
unit DetailField;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,db,qdialogs,GbdbmaskEdit,
cxLabel,QStdCtrls,Graphics;
type
Tdetailfield=class;
TDetailDataLink = class(TDataLink)
private
FDetailField:Tdetailfield;
protected
procedure ActiveChanged; override;
procedure DataSetChanged; override;
public
constructor create(DetailField:TDetailField);
procedure recordchanged(Field:Tfield);override;
end;
TDetailField = class(tpanel)
private
FDatasource:Tdatasource;
FActive:Boolean;
Fdatalink:TDetailDataLink;
//Fdatalink:TGridDataLink;
procedure SetActive(const Value: Boolean);
Procedure CreatedbField;
function getdatasource: Tdatasource;
procedure setdatasource(const Value: Tdatasource);
{ Private declarations }
protected
{ Protected declarations }
property datalink:TDetailDataLink read Fdatalink;
public
constructor Create(AOwner: TComponent);override;
{ Public declarations }
published
{ Published declarations }
property Datasource:Tdatasource read getdatasource write setdatasource ;// NOdefault ;
//property Datasource:Tdatasource read Fdatasource write Fdatasource;
Property Active:Boolean read FActive write SetActive;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('BaoGuo', [TDetailField]);
end;
{ TDetailField }
constructor TDetailField.Create(AOwner: TComponent);
begin
inherited create(Aowner);
TabStop := True;
Fdatalink:=TDetailDataLink.Create(self);
Factive:=true;
caption:=' ';
end;
procedure TDetailField.CreatedbField;
var
sumField:integer;
IntS:integer;
maskedit:Array of TGbdbmaskEdit;
GbLabel:Array of TCxLabel;
begin
sumfield:=Fdatalink.DataSet.FieldCount;
showmessage(inttostr(sumfield));
setlength(Gblabel,sumfield);
setlength(maskedit,sumfield);
if self.Width>=700 then
for ints:=0 to sumfield-1 do
begin
showmessage(inttostr(ints));
GbLabel[ints]:=TcxLabel.Create(self);
GbLabel[ints].Parent:=self;
Gblabel[ints].Style.Color:=clGreen ;
GbLabel[ints].Style.Font.Size:=12;
Gblabel[ints].AutoSize:=False;
GbLabel[ints].Height:=30;
GbLabel[ints].Properties.Alignment.Horz:=taLeftJustify;
GBlabel[ints].Caption:=datasource.DataSet.Fields[ints].FieldName;
Gblabel[ints].Width:=(self.Width) div 7;
GBLabel[ints].Name:='dd'+inttostr(ints);
case (ints mod 3) of
0: GbLabel[ints].Left:=10;
1: GbLabel[ints].Left:=(self.Width-10) div 3+10;
2: GbLabel[ints].Left:=(self.Width-10) div 3*2+10;
end;
case (ints div 3) of
0:GbLabel[ints].Top:=10;
else GbLabel[ints].Top:=(GbLabel[ints].Height)* (ints div 3)+10*(ints div 3+1); ;
end;
if datasource.DataSet.Fields[ints].DataType=ftstring then
begin
maskedit[ints]:=TGbdbmaskEdit.Create(self);
maskedit[ints].parent:=self;
maskedit[ints].Left:=GBlabel[ints].Left+gblabel[ints].Width;
maskedit[ints].Top:=Gblabel[ints].Top;
maskedit[ints].Style.Font.size:=12;
maskedit[ints].Height:=Gblabel[ints].Height;
maskedit[ints].Width:=(self.Width-20) div 3-GBlabel[ints].width;
maskedit[ints].DataBinding.DataSource:=datasource;
maskedit[ints].DataBinding.DataField:=datasource.DataSet.Fields[ints].FieldName;
end;
//else if Fdatasource.DataSet.Fields[ints].DataType=ftstring
end;
end;
function TDetailField.getdatasource: Tdatasource;
begin
result:=Fdatalink.DataSource;
end;
procedure TDetailField.SetActive(const Value: Boolean);
var
i:integer;
begin
showmessage('dd');
if value=Factive then Exit;
If value=True then
Begin
//if Fdatalink.DataSource.DataSet.Active=False then
if (Fdatalink.DataSource=nil) or (Fdatalink.Active=False) then
begin
showmessage(fdatalink.DataSource.Name);
if fdatalink.Active=False then
showmessage('active');
FActive:=False;
end
else
Begin
CreatedbField;
Factive:=true;
end
End
else
begin
showmessage('ddd');
if self.ComponentCount>0 then
for i:=self.ComponentCount-1 downto 0 do
self.Components.Destroy;
FActive:=false;
end;
end;
procedure TDetailField.setdatasource(const Value: Tdatasource);
begin
if Value=Fdatalink.DataSource then Exit;
FDataLink.DataSource := Value;
showmessage(DataSet.Name);//在這里卻無法得到dataset的name
if Fdatalink.DataSource<>nil then
begin
showmessage(Fdatalink.DataSource.Name);
if Fdatalink.Active=true then
showmessage(Fdatalink.DataSet.name);
// CreatedbField;
end;
//if Value <> nil then Value.FreeNotification(Self);
end;
{ TDetailDataLink }
procedure TDetailDataLink.activechanged;
begin
//FDBCtrlGrid.DataSetChanged(False);
// Fdetailfield.Invalidate;
end;
constructor TDetailDataLink.create(DetailField: Tdetailfield);
begin
inherited create;
FDetailField:=DetailField;
VisualControl := true;
RPR;
end;
procedure TDetailDataLink.DataSetChanged;
begin
inherited;
// FDBCtrlGrid.DataSetChanged(False);
end;
procedure TDetailDataLink.recordchanged(Field: Tfield);
begin
inherited;
// FDBCtrlGrid.DataSetChanged(False);
Fdetailfield.Invalidate;
end;
end.
=================================================================
unit DetailField;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,db,qdialogs,GbdbmaskEdit,
cxLabel,QStdCtrls,Graphics;
type
Tdetailfield=class;
TDetailDataLink = class(TDataLink)
private
FDetailField:Tdetailfield;
protected
procedure ActiveChanged; override;
procedure DataSetChanged; override;
public
constructor create(DetailField:TDetailField);
procedure recordchanged(Field:Tfield);override;
end;
TDetailField = class(tpanel)
private
FDatasource:Tdatasource;
FActive:Boolean;
Fdatalink:TDetailDataLink;
//Fdatalink:TGridDataLink;
procedure SetActive(const Value: Boolean);
Procedure CreatedbField;
function getdatasource: Tdatasource;
procedure setdatasource(const Value: Tdatasource);
{ Private declarations }
protected
{ Protected declarations }
property datalink:TDetailDataLink read Fdatalink;
public
constructor Create(AOwner: TComponent);override;
{ Public declarations }
published
{ Published declarations }
property Datasource:Tdatasource read getdatasource write setdatasource ;// NOdefault ;
//property Datasource:Tdatasource read Fdatasource write Fdatasource;
Property Active:Boolean read FActive write SetActive;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('BaoGuo', [TDetailField]);
end;
{ TDetailField }
constructor TDetailField.Create(AOwner: TComponent);
begin
inherited create(Aowner);
TabStop := True;
Fdatalink:=TDetailDataLink.Create(self);
Factive:=true;
caption:=' ';
end;
procedure TDetailField.CreatedbField;
var
sumField:integer;
IntS:integer;
maskedit:Array of TGbdbmaskEdit;
GbLabel:Array of TCxLabel;
begin
sumfield:=Fdatalink.DataSet.FieldCount;
showmessage(inttostr(sumfield));
setlength(Gblabel,sumfield);
setlength(maskedit,sumfield);
if self.Width>=700 then
for ints:=0 to sumfield-1 do
begin
showmessage(inttostr(ints));
GbLabel[ints]:=TcxLabel.Create(self);
GbLabel[ints].Parent:=self;
Gblabel[ints].Style.Color:=clGreen ;
GbLabel[ints].Style.Font.Size:=12;
Gblabel[ints].AutoSize:=False;
GbLabel[ints].Height:=30;
GbLabel[ints].Properties.Alignment.Horz:=taLeftJustify;
GBlabel[ints].Caption:=datasource.DataSet.Fields[ints].FieldName;
Gblabel[ints].Width:=(self.Width) div 7;
GBLabel[ints].Name:='dd'+inttostr(ints);
case (ints mod 3) of
0: GbLabel[ints].Left:=10;
1: GbLabel[ints].Left:=(self.Width-10) div 3+10;
2: GbLabel[ints].Left:=(self.Width-10) div 3*2+10;
end;
case (ints div 3) of
0:GbLabel[ints].Top:=10;
else GbLabel[ints].Top:=(GbLabel[ints].Height)* (ints div 3)+10*(ints div 3+1); ;
end;
if datasource.DataSet.Fields[ints].DataType=ftstring then
begin
maskedit[ints]:=TGbdbmaskEdit.Create(self);
maskedit[ints].parent:=self;
maskedit[ints].Left:=GBlabel[ints].Left+gblabel[ints].Width;
maskedit[ints].Top:=Gblabel[ints].Top;
maskedit[ints].Style.Font.size:=12;
maskedit[ints].Height:=Gblabel[ints].Height;
maskedit[ints].Width:=(self.Width-20) div 3-GBlabel[ints].width;
maskedit[ints].DataBinding.DataSource:=datasource;
maskedit[ints].DataBinding.DataField:=datasource.DataSet.Fields[ints].FieldName;
end;
//else if Fdatasource.DataSet.Fields[ints].DataType=ftstring
end;
end;
function TDetailField.getdatasource: Tdatasource;
begin
result:=Fdatalink.DataSource;
end;
procedure TDetailField.SetActive(const Value: Boolean);
var
i:integer;
begin
showmessage('dd');
if value=Factive then Exit;
If value=True then
Begin
//if Fdatalink.DataSource.DataSet.Active=False then
if (Fdatalink.DataSource=nil) or (Fdatalink.Active=False) then
begin
showmessage(fdatalink.DataSource.Name);
if fdatalink.Active=False then
showmessage('active');
FActive:=False;
end
else
Begin
CreatedbField;
Factive:=true;
end
End
else
begin
showmessage('ddd');
if self.ComponentCount>0 then
for i:=self.ComponentCount-1 downto 0 do
self.Components.Destroy;
FActive:=false;
end;
end;
procedure TDetailField.setdatasource(const Value: Tdatasource);
begin
if Value=Fdatalink.DataSource then Exit;
FDataLink.DataSource := Value;
showmessage(DataSet.Name);//在這里卻無法得到dataset的name
if Fdatalink.DataSource<>nil then
begin
showmessage(Fdatalink.DataSource.Name);
if Fdatalink.Active=true then
showmessage(Fdatalink.DataSet.name);
// CreatedbField;
end;
//if Value <> nil then Value.FreeNotification(Self);
end;
{ TDetailDataLink }
procedure TDetailDataLink.activechanged;
begin
//FDBCtrlGrid.DataSetChanged(False);
// Fdetailfield.Invalidate;
end;
constructor TDetailDataLink.create(DetailField: Tdetailfield);
begin
inherited create;
FDetailField:=DetailField;
VisualControl := true;
RPR;
end;
procedure TDetailDataLink.DataSetChanged;
begin
inherited;
// FDBCtrlGrid.DataSetChanged(False);
end;
procedure TDetailDataLink.recordchanged(Field: Tfield);
begin
inherited;
// FDBCtrlGrid.DataSetChanged(False);
Fdetailfield.Invalidate;
end;
end.