//==============================================================================
//复制控件(支持复制子控件和事件)**********************************************
//==============================================================================
function CopyComponent(Source: TComponent; Parent: TComponent; Owner: TComponent): Boolean; { 返回复制元件是否成功 }
var
vMemoryStream: TMemoryStream;
vComponent: TComponent;
vPropList: PPropList;
vPropInfo: PPropInfo;
vReader: TReader;
i: Integer;
begin
Result := false;
vMemoryStream := TMemoryStream.Create;
vReader := TReader.Create(vMemoryStream, 256);
try
try
vMemoryStream.WriteComponent(Source);
vMemoryStream.Position := 0;
vReader.Parent := Parent;
vComponent := vReader.ReadRootComponent(nil);
for i:=1 to GetPropList(Source, vPropList) do
begin
vPropInfo := vPropList^[i-1];
if vPropInfo^.PropType^.Kind = tkMethod
then SetMethodProp(vComponent, vPropInfo^.Name, GetMethodProp(Source, vPropInfo^.Name));
end;
except
Result := true;
Exit;
end;
finally
vReader.Free;
vMemoryStream.Free;
end;
if Source is TWinControl then
for i:=1 to TWinControl(Source).ControlCount do
if not CopyComponent(TWinControl(Source).Controls[i-1], vComponent, Owner) then Exit;
Result := true;
end;
exam:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm_Main.Button16Click(Sender: TObject);
var Rect: TRect;
i: integer;
begin
StringGrid.Canvas.Brush.Style := bsBDiagonal;
StringGrid.Canvas.Font.Color := clBlack; StringGrid.ColCount := Table1.FieldCount;
for i:=1 to StringGrid.ColCount do
begin
Rect := StringGrid.CellRect(i-1,0);
DrawText(StringGrid.Canvas.Handle,PChar(Table1.Fields[i-1].FieldName),Length(Table1.Fields[i-1].FieldName),Rect,DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end;
end;
//复制控件(支持复制子控件和事件)**********************************************
//==============================================================================
function CopyComponent(Source: TComponent; Parent: TComponent; Owner: TComponent): Boolean; { 返回复制元件是否成功 }
var
vMemoryStream: TMemoryStream;
vComponent: TComponent;
vPropList: PPropList;
vPropInfo: PPropInfo;
vReader: TReader;
i: Integer;
begin
Result := false;
vMemoryStream := TMemoryStream.Create;
vReader := TReader.Create(vMemoryStream, 256);
try
try
vMemoryStream.WriteComponent(Source);
vMemoryStream.Position := 0;
vReader.Parent := Parent;
vComponent := vReader.ReadRootComponent(nil);
for i:=1 to GetPropList(Source, vPropList) do
begin
vPropInfo := vPropList^[i-1];
if vPropInfo^.PropType^.Kind = tkMethod
then SetMethodProp(vComponent, vPropInfo^.Name, GetMethodProp(Source, vPropInfo^.Name));
end;
except
Result := true;
Exit;
end;
finally
vReader.Free;
vMemoryStream.Free;
end;
if Source is TWinControl then
for i:=1 to TWinControl(Source).ControlCount do
if not CopyComponent(TWinControl(Source).Controls[i-1], vComponent, Owner) then Exit;
Result := true;
end;
exam:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm_Main.Button16Click(Sender: TObject);
var Rect: TRect;
i: integer;
begin
StringGrid.Canvas.Brush.Style := bsBDiagonal;
StringGrid.Canvas.Font.Color := clBlack; StringGrid.ColCount := Table1.FieldCount;
for i:=1 to StringGrid.ColCount do
begin
Rect := StringGrid.CellRect(i-1,0);
DrawText(StringGrid.Canvas.Handle,PChar(Table1.Fields[i-1].FieldName),Length(Table1.Fields[i-1].FieldName),Rect,DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end;
end;
解决方案 »
- 浙江联信软件诚聘DELPHI程序员
- 庆贺老王生日,明年还给你散分庆祝!
- ListView的内容制作成报表
- 招募兼职程序员
- 关于websnap的session问题?
- 有哪位想转让delphi5开发人员指南?
- 用H1:=findwindow(nil,'某网页标题')后,如何确定该窗口正在与服务器进行数据通信,或因超时已停止工作?
- 怎样在DBGrid里嵌入其他控件?
- SetWindowsHookEx在win98下返回成功,但dll没有却没有真正注入
- 誰有屏莫抓取圖標的工具軟件!!!!
- 怎样用spcomm读数据??
- 我正在做一个c/s的系统,现在已经接近尾声,我想做一个帮助,就想windows自带的哪个
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm_Main.Button16Click(Sender: TObject);
var Rect: TRect;
i: integer;
begin
StringGrid.Canvas.Brush.Style := bsBDiagonal;
StringGrid.Canvas.Font.Color := clBlack; StringGrid.ColCount := Table1.FieldCount;
for i:=1 to StringGrid.ColCount do
begin
Rect := StringGrid.CellRect(i-1,0);
DrawText(StringGrid.Canvas.Handle,PChar(Table1.Fields[i-1].FieldName),Length(Table1.Fields[i-1].FieldName),Rect,DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end;
end;
//==============================================================================
//复制控件(支持复制子控件和事件)**********************************************
//==============================================================================
function CopyComponent(Source: TComponent; Parent: TComponent; Owner: TComponent): Boolean; { 返回复制元件是否成功 }
var
vMemoryStream: TMemoryStream;
vComponent: TComponent;
vPropList: PPropList;
vPropInfo: PPropInfo;
vReader: TReader;
i: Integer;
begin
Result := false;
vMemoryStream := TMemoryStream.Create;
vReader := TReader.Create(vMemoryStream, 256);
try
try
vMemoryStream.WriteComponent(Source);
vMemoryStream.Position := 0;
vReader.Parent := Parent;
vComponent := vReader.ReadRootComponent(nil);
for i:=1 to GetPropList(Source, vPropList) do
begin
vPropInfo := vPropList^[i-1];
if vPropInfo^.PropType^.Kind = tkMethod
then SetMethodProp(vComponent, vPropInfo^.Name, GetMethodProp(Source, vPropInfo^.Name));
end;
except
Result := true;
Exit;
end;
finally
vReader.Free;
vMemoryStream.Free;
end;
if Source is TWinControl then
for i:=1 to TWinControl(Source).ControlCount do
if not CopyComponent(TWinControl(Source).Controls[i-1], vComponent, Owner) then Exit;
Result := true;
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, Db, DBTables;type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure DBGrid1CellClick(Column: TColumn);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
R: TRect;
begin
if Column.FieldName = 'SIZE' then
begin
with DBGrid1.Canvas do
begin
FillRect(Rect);
R := Rect;
InflateRect(R, -2, -2);
if Column.Field.AsInteger mod 2 = 0 then
DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_CHECKED)
else
DrawFrameControl(Handle, R, DFC_BUTTON, DFCS_BUTTONCHECK);
end;
end;
end;procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
if Column.FieldName = 'SIZE' then
begin
Table1.Edit;
if Column.Field.AsInteger mod 2 = 0 then
Table1.FieldByName('SIZE').AsInteger := Table1.FieldByName('SIZE').AsInteger + 1
else
Table1.FieldByName('SIZE').AsInteger := Table1.FieldByName('SIZE').AsInteger - 1;
Table1.Post;
end;
end;end.