delphi开发activex控件问题,高手请进(100分)

  • 主题发起人 主题发起人 emailqjc
  • 开始时间 开始时间
E

emailqjc

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能讲一下用delphi做ocx的详细过程及注意事项,
在里面如何增加一函数,为什么我在ocx里写的函数(Get_StrID)在调用时候不能看到,但函数ConnDB在调用时候能看到[?]?
代码如下:
unit ActiveQryFilter_HDImpl;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ActiveX, AxCtrls, ActiveQryFilter_HDProj_TLB, StdVcl, StdCtrls, Buttons,
DB, ADODB, Grids, DBGrids, ExtCtrls;

type
TActiveQryFilter_HD = class(TActiveForm, IActiveQryFilter_HD)
Panel1: TPanel;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
BitBtn_Find: TBitBtn;
BitBtn_Load: TBitBtn;
BitBtn_Select: TBitBtn;
BitBtn4: TBitBtn;
RadioGroup1: TRadioGroup;
Label1: TLabel;
Ed_value: TEdit;
procedure BitBtn4Click(Sender: TObject);
procedure DBGrid1KeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure DBGrid1DblClick(Sender: TObject);
procedure BitBtn_SelectClick(Sender: TObject);
procedure BitBtn_FindClick(Sender: TObject);
private
{ Private declarations }
FEvents: IActiveQryFilter_HDEvents;
procedure ActivateEvent(Sender: TObject);
procedure ClickEvent(Sender: TObject);
procedure CreateEvent(Sender: TObject);
procedure DblClickEvent(Sender: TObject);
procedure DeactivateEvent(Sender: TObject);
procedure DestroyEvent(Sender: TObject);
procedure KeyPressEvent(Sender: TObject;
var Key: Char);
procedure PaintEvent(Sender: TObject);
protected
{ Protected declarations }
procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
override;
procedure EventSinkChanged(const EventSink: IUnknown);
override;
function Get_Active: WordBool;
safecall;
function Get_AlignDisabled: WordBool;
safecall;
function Get_AutoScroll: WordBool;
safecall;
function Get_AutoSize: WordBool;
safecall;
function Get_AxBorderStyle: TxActiveFormBorderStyle;
safecall;
function Get_Caption: WideString;
safecall;
function Get_Color: OLE_COLOR;
safecall;
function Get_DoubleBuffered: WordBool;
safecall;
function Get_DropTarget: WordBool;
safecall;
function Get_Enabled: WordBool;
safecall;
function Get_Font: IFontDisp;
safecall;
function Get_HelpFile: WideString;
safecall;
function Get_KeyPreview: WordBool;
safecall;
function Get_PixelsPerInch: Integer;
safecall;
function Get_PrintScale: TxPrintScale;
safecall;
function Get_Scaled: WordBool;
safecall;
function Get_ScreenSnap: WordBool;
safecall;
function Get_SnapBuffer: Integer;
safecall;
function Get_Visible: WordBool;
safecall;
function Get_VisibleDockClientCount: Integer;
safecall;
procedure _Set_Font(var Value: IFontDisp);
safecall;
procedure Set_AutoScroll(Value: WordBool);
safecall;
procedure Set_AutoSize(Value: WordBool);
safecall;
procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
safecall;
procedure Set_Caption(const Value: WideString);
safecall;
procedure Set_Color(Value: OLE_COLOR);
safecall;
procedure Set_DoubleBuffered(Value: WordBool);
safecall;
procedure Set_DropTarget(Value: WordBool);
safecall;
procedure Set_Enabled(Value: WordBool);
safecall;
procedure Set_Font(const Value: IFontDisp);
safecall;
procedure Set_HelpFile(const Value: WideString);
safecall;
procedure Set_KeyPreview(Value: WordBool);
safecall;
procedure Set_PixelsPerInch(Value: Integer);
safecall;
procedure Set_PrintScale(Value: TxPrintScale);
safecall;
procedure Set_Scaled(Value: WordBool);
safecall;
procedure Set_ScreenSnap(Value: WordBool);
safecall;
procedure Set_SnapBuffer(Value: Integer);
safecall;
procedure Set_Visible(Value: WordBool);
safecall;

procedure Set_StrID(const Value: WideString);
safecall;
public
{ Public declarations }
procedure Initialize;
override;
procedure ConnDB(const AStrConn: WideString);
safecall;
function Get_StrID: WideString;
safecall;
end;


var
RtStr:WideString='';
implementation

uses ComObj, ComServ;

{$R *.DFM}

{ TActiveQryFilter_HD }

procedure TActiveQryFilter_HD.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
begin

{ Define property pages here. Property pages are defined by calling
DefinePropertyPage with the class id of the page. For example,
DefinePropertyPage(Class_ActiveQryFilter_HDPage);
}
end;


procedure TActiveQryFilter_HD.EventSinkChanged(const EventSink: IUnknown);
begin

FEvents := EventSink as IActiveQryFilter_HDEvents;
inherited EventSinkChanged(EventSink);
end;


procedure TActiveQryFilter_HD.Initialize;
begin

inherited Initialize;
OnActivate := ActivateEvent;
OnClick := ClickEvent;
OnCreate := CreateEvent;
OnDblClick := DblClickEvent;
OnDeactivate := DeactivateEvent;
OnDestroy := DestroyEvent;
OnKeyPress := KeyPressEvent;
OnPaint := PaintEvent;
end;


function TActiveQryFilter_HD.Get_Active: WordBool;
begin

Result := Active;
end;


function TActiveQryFilter_HD.Get_AlignDisabled: WordBool;
begin

Result := AlignDisabled;
end;


function TActiveQryFilter_HD.Get_AutoScroll: WordBool;
begin

Result := AutoScroll;
end;


function TActiveQryFilter_HD.Get_AutoSize: WordBool;
begin

Result := AutoSize;
end;


function TActiveQryFilter_HD.Get_AxBorderStyle: TxActiveFormBorderStyle;
begin

Result := Ord(AxBorderStyle);
end;


function TActiveQryFilter_HD.Get_Caption: WideString;
begin

Result := WideString(Caption);
end;


function TActiveQryFilter_HD.Get_Color: OLE_COLOR;
begin

Result := OLE_COLOR(Color);
end;


function TActiveQryFilter_HD.Get_DoubleBuffered: WordBool;
begin

Result :=do
ubleBuffered;
end;


function TActiveQryFilter_HD.Get_DropTarget: WordBool;
begin

Result := DropTarget;
end;


function TActiveQryFilter_HD.Get_Enabled: WordBool;
begin

Result := Enabled;
end;


function TActiveQryFilter_HD.Get_Font: IFontDisp;
begin

GetOleFont(Font, Result);
end;


function TActiveQryFilter_HD.Get_HelpFile: WideString;
begin

Result := WideString(HelpFile);
end;


function TActiveQryFilter_HD.Get_KeyPreview: WordBool;
begin

Result := KeyPreview;
end;


function TActiveQryFilter_HD.Get_PixelsPerInch: Integer;
begin

Result := PixelsPerInch;
end;


function TActiveQryFilter_HD.Get_PrintScale: TxPrintScale;
begin

Result := Ord(PrintScale);
end;


function TActiveQryFilter_HD.Get_Scaled: WordBool;
begin

Result := Scaled;
end;


function TActiveQryFilter_HD.Get_ScreenSnap: WordBool;
begin

Result := ScreenSnap;
end;


function TActiveQryFilter_HD.Get_SnapBuffer: Integer;
begin

Result := SnapBuffer;
end;


function TActiveQryFilter_HD.Get_Visible: WordBool;
begin

Result := Visible;
end;


function TActiveQryFilter_HD.Get_VisibleDockClientCount: Integer;
begin

Result := VisibleDockClientCount;
end;


procedure TActiveQryFilter_HD._Set_Font(var Value: IFontDisp);
begin

SetOleFont(Font, Value);
end;


procedure TActiveQryFilter_HD.ActivateEvent(Sender: TObject);
begin

if FEvents <> nil then
FEvents.OnActivate;
end;


procedure TActiveQryFilter_HD.ClickEvent(Sender: TObject);
begin

if FEvents <> nil then
FEvents.OnClick;
end;


procedure TActiveQryFilter_HD.CreateEvent(Sender: TObject);
begin

if FEvents <> nil then
FEvents.OnCreate;
end;


procedure TActiveQryFilter_HD.DblClickEvent(Sender: TObject);
begin

if FEvents <> nil then
FEvents.OnDblClick;
end;


procedure TActiveQryFilter_HD.DeactivateEvent(Sender: TObject);
begin

if FEvents <> nil then
FEvents.OnDeactivate;
end;


procedure TActiveQryFilter_HD.DestroyEvent(Sender: TObject);
begin

if FEvents <> nil then
FEvents.OnDestroy;
end;


procedure TActiveQryFilter_HD.KeyPressEvent(Sender: TObject;
var Key: Char);
var
TempKey: Smallint;
begin

TempKey := Smallint(Key);
if FEvents <> nil then
FEvents.OnKeyPress(TempKey);
Key := Char(TempKey);
end;


procedure TActiveQryFilter_HD.PaintEvent(Sender: TObject);
begin

if FEvents <> nil then
FEvents.OnPaint;
end;


procedure TActiveQryFilter_HD.Set_AutoScroll(Value: WordBool);
begin

AutoScroll := Value;
end;


procedure TActiveQryFilter_HD.Set_AutoSize(Value: WordBool);
begin

AutoSize := Value;
end;


procedure TActiveQryFilter_HD.Set_AxBorderStyle(
Value: TxActiveFormBorderStyle);
begin

AxBorderStyle := TActiveFormBorderStyle(Value);
end;


procedure TActiveQryFilter_HD.Set_Caption(const Value: WideString);
begin

Caption := TCaption(Value);
end;


procedure TActiveQryFilter_HD.Set_Color(Value: OLE_COLOR);
begin

Color := TColor(Value);
end;


procedure TActiveQryFilter_HD.Set_DoubleBuffered(Value: WordBool);
begin

do
ubleBuffered := Value;
end;


procedure TActiveQryFilter_HD.Set_DropTarget(Value: WordBool);
begin

DropTarget := Value;
end;


procedure TActiveQryFilter_HD.Set_Enabled(Value: WordBool);
begin

Enabled := Value;
end;


procedure TActiveQryFilter_HD.Set_Font(const Value: IFontDisp);
begin

SetOleFont(Font, Value);
end;


procedure TActiveQryFilter_HD.Set_HelpFile(const Value: WideString);
begin

HelpFile := String(Value);
end;


procedure TActiveQryFilter_HD.Set_KeyPreview(Value: WordBool);
begin

KeyPreview := Value;
end;


procedure TActiveQryFilter_HD.Set_PixelsPerInch(Value: Integer);
begin

PixelsPerInch := Value;
end;


procedure TActiveQryFilter_HD.Set_PrintScale(Value: TxPrintScale);
begin

PrintScale := TPrintScale(Value);
end;


procedure TActiveQryFilter_HD.Set_Scaled(Value: WordBool);
begin

Scaled := Value;
end;


procedure TActiveQryFilter_HD.Set_ScreenSnap(Value: WordBool);
begin

ScreenSnap := Value;
end;


procedure TActiveQryFilter_HD.Set_SnapBuffer(Value: Integer);
begin

SnapBuffer := Value;
end;


procedure TActiveQryFilter_HD.Set_Visible(Value: WordBool);
begin

Visible := Value;
end;


procedure TActiveQryFilter_HD.BitBtn4Click(Sender: TObject);
begin

close;
end;


procedure TActiveQryFilter_HD.ConnDB(const AStrConn: WideString);
begin

ADOConnection1.Close;

self.ADOConnection1.ConnectionString:=AStrConn;
self.ADOConnection1.Open;
with self.ADOQuery1do

begin

close;
sql.Clear;
sql.Text:=' select * from studentinfo ';
open;
first;

end;

end;


procedure TActiveQryFilter_HD.DBGrid1KeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin

if key=13 then
self.BitBtn_Select.Click;
end;


procedure TActiveQryFilter_HD.DBGrid1DblClick(Sender: TObject);
begin

self.BitBtn_Select.Click;
end;


procedure TActiveQryFilter_HD.BitBtn_SelectClick(Sender: TObject);
begin

if not self.ADOQuery1.Active then
exit;
if self.ADOQuery1.RecordCount=0 then
exit;
RtStr:=Trim(self.ADOQuery1.fieldbyname('id').AsString);
end;


function TActiveQryFilter_HD.Get_StrID: WideString;
begin

result:=RtStr;
end;


procedure TActiveQryFilter_HD.Set_StrID(const Value: WideString);
begin


end;


procedure TActiveQryFilter_HD.BitBtn_FindClick(Sender: TObject);
begin

self.ADOQuery1.Locate('','',tlocateop)
end;


initialization
TActiveFormFactory.Create(
ComServer,
TActiveFormControl,
TActiveQryFilter_HD,
Class_ActiveQryFilter_HD,
1,
'',
OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
tmApartment);
end.
 
怎么没人回答呢?求名啊
 
我用delphi写的ocx安装后为什么不能卸载,提示未知软件异常,我该怎么办??
 
后退
顶部