当使用ActiveXForm时,如何调用其他Form?(50分)

  • 主题发起人 主题发起人 黑狗
  • 开始时间 开始时间

黑狗

Unregistered / Unconfirmed
GUEST, unregistred user!
SearchForm.Show;后出错。如何解决?是程序问题还是系统问题?
我要点击一个按钮,然后切换到另外一页,或弹出另一个form均可。
详解!
以下是源代码:通过Ado连Sql7的ActiveXForm的做法。但调用
searchform出错.求解。

unit testFormImpl1;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ActiveX, AxCtrls, testFormProj1_TLB, StdVcl, StdCtrls, DB, ExtCtrls,
DBCtrls, Grids, DBGrids, ADODB, ComCtrls, ToolWin, Buttons, ActiveButton,
Mask, CheckLst;

type
TMainForm = class(TActiveForm, ItestFormX)
CoolBar1: TCoolBar;
PageControl1: TPageControl;
StatusBar2: TStatusBar;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Panel1: TPanel;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ToolBar1: TToolBar;
ActiveButton1: TActiveButton;
ADOQuery1DSDesigner: TIntegerField;
ADOQuery1DSDesigner2: TStringField;
ADOQuery1DSDesigner3: TStringField;
ADOQuery1DSDesigner4: TStringField;
ADOQuery1DSDesigner5: TStringField;
ADOQuery1DSDesigner6: TFloatField;
ADOQuery1DSDesigner7: TStringField;
GroupBox1: TGroupBox;
DBText1: TDBText;
DBEdit1: TDBEdit;
DBComboBox1: TDBComboBox;
DBEdit2: TDBEdit;
DBMemo1: TDBMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Panel2: TPanel;
Panel3: TPanel;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBNavigator1: TDBNavigator;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
CheckListBox1: TCheckListBox;
ActiveButton2: TActiveButton;
CheckListBox2: TCheckListBox;
ActiveButton3: TActiveButton;
ActiveButton4: TActiveButton;
ActiveButton5: TActiveButton;
procedure ActiveButton1Click(Sender: TObject);
procedure ActiveButton2Click(Sender: TObject);
procedure CheckListBox1ClickCheck(Sender: TObject);
procedure CheckListBox2ClickCheck(Sender: TObject);
procedure ActiveButton3Click(Sender: TObject);
procedure ActiveButton4Click(Sender: TObject);
procedure ActiveButton5Click(Sender: TObject);
private
{ Private declarations }
FEvents: ItestFormXEvents;
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_Cursor: Smallint
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_HelpKeyword: WideString
safecall;
function Get_HelpType: TxHelpType
safecall;
function Get_KeyPreview: WordBool
safecall;
function Get_PixelsPerInch: Integer
safecall;
function Get_PrintScale: TxPrintScale
safecall;
function Get_Scaled: WordBool
safecall;
function Get_Visible: WordBool
safecall;
function Get_VisibleDockClientCount: Integer
safecall;
procedure _Set_Font(var Value: IFontDisp)
safecall;
procedure AboutBox
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_Cursor(Value: Smallint)
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_HelpKeyword(const Value: WideString)
safecall;
procedure Set_HelpType(Value: TxHelpType)
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_Visible(Value: WordBool)
safecall;
public
itemchima,itemcolor:string;
{ Public declarations }
procedure Initialize
override;
end;

implementation

uses ComObj, ComServ, About1, Unit1;

{$R *.DFM}

{ TtestFormX }

procedure TMainForm.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_testFormXPage)
}
end;

procedure TMainForm.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as ItestFormXEvents;
inherited EventSinkChanged(EventSink);
end;

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

function TMainForm.Get_Active: WordBool;
begin
Result := Active;
end;

function TMainForm.Get_AlignDisabled: WordBool;
begin
Result := AlignDisabled;
end;

function TMainForm.Get_AutoScroll: WordBool;
begin
Result := AutoScroll;
end;

function TMainForm.Get_AutoSize: WordBool;
begin
Result := AutoSize;
end;

function TMainForm.Get_AxBorderStyle: TxActiveFormBorderStyle;
begin
Result := Ord(AxBorderStyle);
end;

function TMainForm.Get_Caption: WideString;
begin
Result := WideString(Caption);
end;

function TMainForm.Get_Color: OLE_COLOR;
begin
Result := OLE_COLOR(Color);
end;

function TMainForm.Get_Cursor: Smallint;
begin
Result := Smallint(Cursor);
end;

function TMainForm.Get_DoubleBuffered: WordBool;
begin
Result := DoubleBuffered;
end;

function TMainForm.Get_DropTarget: WordBool;
begin
Result := DropTarget;
end;

function TMainForm.Get_Enabled: WordBool;
begin
Result := Enabled;
end;

function TMainForm.Get_Font: IFontDisp;
begin
GetOleFont(Font, Result);
end;

function TMainForm.Get_HelpFile: WideString;
begin
Result := WideString(HelpFile);
end;

function TMainForm.Get_HelpKeyword: WideString;
begin
Result := WideString(HelpKeyword);
end;

function TMainForm.Get_HelpType: TxHelpType;
begin
Result := Ord(HelpType);
end;

function TMainForm.Get_KeyPreview: WordBool;
begin
Result := KeyPreview;
end;

function TMainForm.Get_PixelsPerInch: Integer;
begin
Result := PixelsPerInch;
end;

function TMainForm.Get_PrintScale: TxPrintScale;
begin
Result := Ord(PrintScale);
end;

function TMainForm.Get_Scaled: WordBool;
begin
Result := Scaled;
end;

function TMainForm.Get_Visible: WordBool;
begin
Result := Visible;
end;

function TMainForm.Get_VisibleDockClientCount: Integer;
begin
Result := VisibleDockClientCount;
end;

procedure TMainForm._Set_Font(var Value: IFontDisp);
begin
SetOleFont(Font, Value);
end;

procedure TMainForm.AboutBox;
begin
ShowtestFormXAbout;
end;

procedure TMainForm.ActivateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnActivate;
end;

procedure TMainForm.ClickEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnClick;
end;

procedure TMainForm.CreateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnCreate;
end;

procedure TMainForm.DblClickEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDblClick;
end;

procedure TMainForm.DeactivateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDeactivate;
end;

procedure TMainForm.DestroyEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDestroy;
end;

procedure TMainForm.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 TMainForm.PaintEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnPaint;
end;

procedure TMainForm.Set_AutoScroll(Value: WordBool);
begin
AutoScroll := Value;
end;

procedure TMainForm.Set_AutoSize(Value: WordBool);
begin
AutoSize := Value;
end;

procedure TMainForm.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
begin
AxBorderStyle := TActiveFormBorderStyle(Value);
end;

procedure TMainForm.Set_Caption(const Value: WideString);
begin
Caption := TCaption(Value);
end;

procedure TMainForm.Set_Color(Value: OLE_COLOR);
begin
Color := TColor(Value);
end;

procedure TMainForm.Set_Cursor(Value: Smallint);
begin
Cursor := TCursor(Value);
end;

procedure TMainForm.Set_DoubleBuffered(Value: WordBool);
begin
DoubleBuffered := Value;
end;

procedure TMainForm.Set_DropTarget(Value: WordBool);
begin
DropTarget := Value;
end;

procedure TMainForm.Set_Enabled(Value: WordBool);
begin
Enabled := Value;
end;

procedure TMainForm.Set_Font(const Value: IFontDisp);
begin
SetOleFont(Font, Value);
end;

procedure TMainForm.Set_HelpFile(const Value: WideString);
begin
HelpFile := String(Value);
end;

procedure TMainForm.Set_HelpKeyword(const Value: WideString);
begin
HelpKeyword := String(Value);
end;

procedure TMainForm.Set_HelpType(Value: TxHelpType);
begin
HelpType := THelpType(Value);
end;

procedure TMainForm.Set_KeyPreview(Value: WordBool);
begin
KeyPreview := Value;
end;

procedure TMainForm.Set_PixelsPerInch(Value: Integer);
begin
PixelsPerInch := Value;
end;

procedure TMainForm.Set_PrintScale(Value: TxPrintScale);
begin
PrintScale := TPrintScale(Value);
end;

procedure TMainForm.Set_Scaled(Value: WordBool);
begin
Scaled := Value;
end;

procedure TMainForm.Set_Visible(Value: WordBool);
begin
Visible := Value;
end;

procedure TMainForm.ActiveButton1Click(Sender: TObject);
begin
ADOQuery1.Open;
StatusBar2.SimpleText:='成功连接上服务器';
end;

procedure TMainForm.ActiveButton2Click(Sender: TObject);
var
i:integer;
begin
DBEdit2.Text:='';
Delete(itemchima,1,1);
DBEdit2.Text:=itemchima;
itemchima:='';
for i:=0 to CheckListBox1.Items.Count-1 do
if CheckListBox1.Checked then
CheckListBox1.Checked:=false;
end;
procedure TMainForm.CheckListBox1ClickCheck(Sender: TObject);
begin
if CheckListBox1.Checked[CheckListBox1.ItemIndex] then
itemchima:=itemchima+','+CheckListBox1.Items[CheckListBox1.ItemIndex];
end;

procedure TMainForm.CheckListBox2ClickCheck(Sender: TObject);
begin
if CheckListBox2.Checked[CheckListBox2.ItemIndex] then
itemcolor:=itemcolor+','+CheckListBox2.Items[CheckListBox2.ItemIndex];
end;

procedure TMainForm.ActiveButton3Click(Sender: TObject);
var
i:integer;
begin
DBEdit3.Text:='';
Delete(itemcolor,1,1);
DBEdit3.Text:=itemcolor;
itemcolor:='';
for i:=0 to CheckListBox2.Items.Count-1 do
if CheckListBox2.Checked then
CheckListBox2.Checked:=false;
end;

procedure TMainForm.ActiveButton4Click(Sender: TObject);
begin
ADOQuery1.Close;
end;

procedure TMainForm.ActiveButton5Click(Sender: TObject);
begin
SearchForm.Show;
end;

initialization
TActiveFormFactory.Create(
ComServer,
TActiveFormControl,
TMainForm,
Class_MainForm,
1,
'',
OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
tmApartment);
end.
 
你的SearchForm创建了吗

SearchForm := TSearchForm.create(nil);
SearchForm.showmodel;
SearchForm.free;
 
procedure Tform1.button1click(sender:TObject);
begin
form2:=Tform2.create(self);//这里创建一个实例
try
form2.showmodal
//
finally
form2.free
//
end;
end;
 
ActiveForm只能是一个,不能做到多个Form
要么你做成多个ActiveForm,要么你在ActiveForm里
放入多个Panel,仿成多个Form
 
不同意sun7wind:
我做过这样的东西
用 狼牙 的方法就可以了
 
你试了吗?
 
可是动态创建也有问题啊,如果不是showmodel,就会出现form脱离IE界面的问题
 
接受答案了.
 
后退
顶部