救急,下面代码该如何翻译成BCB的代码?300分。(300分)

  • 主题发起人 主题发起人 djdsz
  • 开始时间 开始时间
D

djdsz

Unregistered / Unconfirmed
GUEST, unregistred user!
unit ICQControl;

interface

implementation

uses Windows,Messages,Classes,forms;

type
TICQCtl = class
private
FControl : HWND;
Handle : HWND;
protected

public
constructor Create;
Destructor Destroy;override;
procedure WNDPROC(var Message:TMessage);
end;

var
ICQIns : TICQCtl;

{ TICQCtl }

constructor TICQCtl.Create;
begin
inherited Create;
handle:=allocatehwnd(WNDPROC);
sendMessage(Application.MainForm.Handle,wm_user+$301,handle,0);
sendMessage(FControl,wm_user+$302,0,0);
end;

destructor TICQCtl.Destroy;
begin
DeallocateHWnd(handle);
inherited;
end;

procedure TICQCtl.WNDPROC(var Message: TMessage);
begin
try
with message do
case msg of
wm_user+$4: FControl:=WParam;
end;
except
end;
end;

initialization
ICQIns := TICQCtl.Create;
finalization
ICQIns.Free;
end.
 
难道在C++中无法完成上面功能吗?还是DFW中没有高手?
 
这是一个组件,BCB的组件本来用Pas语言,何必换成BCB语言呢?
 
kkyy说的对,BCB可以直接使用Delphi组件!
 
是啊,为什么要换啊?
 
这不是一个组件,是我写的一个类,但是在单元初始化中,创建了该类的实例。
在Delphi中我写的系统一般都是使用动态装载包,包中放有Form。下面是一个例子:

unit AppinfUnit;
{$J+}

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BaseUnitA, ComCtrls, dxtree, DB, dxLayoutControl, dxExEdtr,
dxEdLib, dxDBELib, dxCntner, dxEditor, dxDBTLCl, dxGrClms, dxTL,
dxDBCtrl, dxDBGrid, KsThemeEngine, KsHooks, KsForms, KsThemeForms,
KsMessages, KsThemeMessages, ImgList, StdActns, ActnList, DBClient,
PubDataSet, AutoDataSet, dxLayoutLookAndFeels, Menus, ToolWin, cxControls,
KsControls, KsButtons, KsThemeButtons, KsItems, KsThemeItems, KsMenus,
KsThemeMenus, dxInspRw, dxDBInRw, dxDBInsp, dxInspct;

type
TAppinf = class(TBaseFmt)
MainDataAPP_ID: TStringField;
MainDataAPP_NM: TStringField;
MainDataAPP_ST: TFMTBCDField;
MainDataAPP_RG: TFMTBCDField;
MainDataAPP_VR: TStringField;
MainDataAPP_RF: TBlobField;
MainDataAPP_IC: TBlobField;
MainDataAPP_DA: TBlobField;
dxLayoutControl1Group1: TdxLayoutGroup;
dxLayoutControl1Group3: TdxLayoutGroup;
ImageList2: TImageList;
dxTreeView1: TdxTreeView;
dxLayoutControl1Item1: TdxLayoutItem;
dxDBInspector1: TdxDBInspector;
dxLayoutControl1Item3: TdxLayoutItem;
dxDBInspector1APP_ID: TdxInspectorDBMaskRow;
dxDBInspector1APP_NM: TdxInspectorDBMaskRow;
dxDBInspector1APP_VR: TdxInspectorDBMaskRow;
dxDBInspector1APP_IC: TdxInspectorDBGraphicRow;
dxDBInspector1APP_ST: TdxInspectorDBButtonRow;
dxDBInspector1APP_RG: TdxInspectorDBButtonRow;
dxDBInspector1APP_RF: TdxInspectorDBMemoRow;
dxDBInspector1Row8: TdxInspectorDBButtonRow;
dxDBInspector1Row9: TdxInspectorDBRow;
dxDBInspector1Row10: TdxInspectorDBRow;
dxDBInspector1Row11: TdxInspectorDBRow;
dxLayoutControl1Group2: TdxLayoutGroup;
dxDBGrid1: TdxDBGrid;
dxLayoutControl1Item2: TdxLayoutItem;
dxDBGrid1APP_ID: TdxDBGridMaskColumn;
dxDBGrid1APP_NM: TdxDBGridMaskColumn;
dxDBGrid1APP_ST: TdxDBGridColumn;
dxDBGrid1APP_RG: TdxDBGridColumn;
dxDBGrid1APP_VR: TdxDBGridMaskColumn;
dxDBGrid1APP_RF: TdxDBGridColumn;
dxDBGrid1APP_IC: TdxDBGridGraphicColumn;
dxDBGrid1APP_DA: TdxDBGridColumn;
dxLayoutControl1Group5: TdxLayoutGroup;
procedure dxDBGraphicEdit1GetGraphicClass(Sender: TObject;
var GraphicClass: TGraphicClass);
procedure dxDBGrid1APP_ICGetGraphicClass(Sender: TObject;
Node: TdxTreeListNode
var GraphicClass: TGraphicClass);
procedure MainDataAfterOpen(DataSet: TDataSet);
procedure MainDataAfterScroll(DataSet: TDataSet);
procedure dxTreeView1Change(Sender: TObject
Node: TTreeNode);
procedure dxTreeView1Changing(Sender: TObject
Node: TTreeNode;
var AllowChange: Boolean);
procedure dxDBInspector1APP_STButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
procedure dxDBInspector1APP_RGButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
procedure dxDBInspector1Row8ButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
procedure MainSourceStateChange(Sender: TObject);
procedure MainDataBeforeEdit(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;

implementation

uses cvlanguage, AppSetUnit, AppSecurityUnit, DesignUnit;

{$R *.dfm}

procedure TAppinf.dxDBGraphicEdit1GetGraphicClass(Sender: TObject;
var GraphicClass: TGraphicClass);
begin
inherited;
GraphicClass:=TIcon;
end;

procedure TAppinf.dxDBGrid1APP_ICGetGraphicClass(Sender: TObject;
Node: TdxTreeListNode
var GraphicClass: TGraphicClass);
begin
inherited;
GraphicClass:=TIcon;
end;

procedure TAppinf.MainDataAfterOpen(DataSet: TDataSet);
var
s:string;
ic:Ticon;
stream:Tstream;
cds:TClientDataSet;
const
Lenv:array[-1..7] of TTreeNode=(nil,nil,nil,nil,nil,nil,nil,nil,nil);
begin
inherited;
dxTreeView1.Items.BeginUpdate;
dxTreeView1.Items.Clear;
cds:=TClientDataSet.Create(self);
try
cds.CloneCursor(maindata,true,true);
cds.First;
while not cds.Eof do
begin
s:=cds.fieldbyname('App_id').AsString;
lenv[length(s) div 2]:=dxTreeView1.Items.AddChildObject(lenv[(length(s) div 2) - 1],cds.fieldbyname('app_nm').AsString,cds.GetBookmark);
Stream:=TMemoryStream.Create;
try
TblobField(cds.fieldbyname('app_ic')).SaveToStream(stream);
if stream.Size>0 then
begin
ic:=Ticon.Create;
try
stream.Seek(soFromBeginning,0);
ic.LoadFromStream(stream);
lenv[length(s) div 2].ImageIndex:=imagelist2.AddIcon(ic);
finally
ic.Free;
end;
end else
lenv[length(s) div 2].ImageIndex:=0;
finally
stream.Free;
end;
lenv[length(s) div 2].Data:=cds.GetBookmark;
cds.Next;
end;
finally
cds.Free;
end;
dxTreeView1.Items.EndUpdate;
end;

procedure TAppinf.MainDataAfterScroll(DataSet: TDataSet);
var
i:integer;
p:pointer;
begin
inherited;
p:=maindata.GetBookmark;
for i:=0 to dxTreeview1.Items.Count-1 do
if maindata.CompareBookmarks(dxTreeview1.items.data,p)=0 then
begin
dxTreeview1.Selected:=dxTreeview1.items;
exit;
end;
end;

procedure TAppinf.dxTreeView1Change(Sender: TObject
Node: TTreeNode);
begin
inherited;
maindata.GotoBookmark(node.Data);
end;

procedure TAppinf.dxTreeView1Changing(Sender: TObject
Node: TTreeNode;
var AllowChange: Boolean);
begin
inherited;
AllowChange:=not (MainData.State in dsEditModes);
end;

procedure TAppinf.dxDBInspector1APP_STButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
begin
inherited;
with TAppSet.Create(nil,vararrayof([integer(mainsource),'app_ic',maindataapp_id.asstring+' '+maindataapp_nm.asstring,integer(maindataapp_st),maindata.state in dsEditModes])) do
try
showmodal;
finally
free;
end;
end;

procedure TAppinf.dxDBInspector1APP_RGButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
begin
inherited;
with TAppSecurity.Create(nil,vararrayof([integer(mainsource),'app_ic',maindataapp_id.asstring+' '+maindataapp_nm.asstring,integer(maindataapp_rg),maindata.state in dsEditModes])) do
try
showmodal;
finally
free;
end;
end;

procedure TAppinf.dxDBInspector1Row8ButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
begin
inherited;
if MainData.State in dseditmodes then
with TDesignForm.Create(nil,vararrayof([integer(maincon),integer(maindataApp_da)])) do
try
ShowModal;
finally
Free;
end;
end;

procedure TAppinf.MainSourceStateChange(Sender: TObject);
begin
inherited;
dxLayoutControl1Group2.Enabled:=not (MainData.State in dseditmodes);
dxLayoutControl1Group3.Enabled:=not (MainData.State in dseditmodes);
end;

procedure TAppinf.MainDataBeforeEdit(DataSet: TDataSet);
begin
inherited;
MainDataApp_nm.FocusControl;
end;

initialization
RegisterClass(TAppinf);
finalization
UnRegisterClass(TAppinf);
end.

现在我想知道
initialization
RegisterClass(TAppinf);
finalization
UnRegisterClass(TAppinf);
end.
在BCB中到底该怎么实现。谢谢
 
类也是一个组件啊,也可以把它作为组件安装就可以用了。
我的水平也很差,呵呵,不知道BCB中相似的功能。
 
不用注册类都可以直接引用的啦。
我觉得上面的代码转换过来是很简单的,你自己先试一下好了,不行再帮你搞
 
不會吧﹐這么多我會暈的
 
>>initialization和finalization在BCB中到底该怎么实现
这不是C++的编程思想,不要生搬硬套。在Delphi中,由initialization包起来的代码是在
程序启动时执行,由finalization包起来的代码是在程序终止前执行,这是Pascal语言条理
清晰,语法严谨的一个表现,但这只是一个可选的设置,在Delphi中也不是一定要这样做的。
可以由其它的实现方法替代,比如把原来放在initialization段中的代码放在项目文件代码
的Application->Initialize前后,把finalization段中的代码放在项目文件代码的最后部分。
 
to chenxz:
不用注册也可以引用?在普通的应用中可以,但前提是我在使用动态包,我要使用
类的名字得到类引用,然后创建类实例。
to Sachow:
放到Application->Initialize前后,那么系统已经没有灵活性了。要知道,主程序只是
容器,没有动态装载的包,主程序是不能完成任何功能的。主程序根本不知道系统到底有
哪些类,我只是将类先注册,然后从数据库中查询出一个模块所对应的类名称,然后根据
类名称创建类实例。
to All:
大家在BCB中是怎么实现动态装载包的呢?
 
只知道动态加载包要用LoadPackage,导入函数用__declspec(packages),但怎么用找不到资料,
帮助上也没有示例(package support routines)。
 
看来大富翁中是没有人知道了,或者是没人愿意帮忙了。撤
 
后退
顶部