我是新手,問幾個DELPHI ActiveForm比較低級的問題,請各位大哥不吝指點,謝謝。 |
尚未結案
|
yzml
一般會員 ![]() ![]() 發表:4 回覆:4 積分:1 註冊:2004-12-26 發送簡訊給我 |
問題一:
在不添加任何的屬性情況下,DELPHI的ActiveForm自帶了很多屬性,如下: Visible,AutoScroll,AutoSize, AxBorderStyle, Caption, Color, Font, KeyPreview, PixelsPerInch, PrintScale, Scaled, Active, DropTarget, HelpFile, ScreenSnap, SnapBuffer, DoubleBuffered, AlignDisabled, VisibleDockClientCount, Enabled. 在用FrontPage等網頁製作軟體中插入用DELPHI開發的ActiveX控制項時,這些DELPHI自帶的屬性參數被帶入HTML,如下:
〈object classid="clsid:977AEDDD-6591-49D6-8EA3-C0DF2440EE23" id="AddressDialogActiveForm1" width="594" height="401"〉
〈param name="Visible" value="0"〉
〈param name="AutoScroll" value="0"〉
〈param name="AutoSize" value="0"〉
〈param name="AxBorderStyle" value="1"〉
〈param name="Caption" value="AddressDialogActiveForm"〉
〈param name="Color" value="2147483663"〉
〈param name="Font" value="MS Sans Serif"〉
〈param name="KeyPreview" value="0"〉
〈param name="PixelsPerInch" value="96"〉
〈param name="PrintScale" value="1"〉
〈param name="Scaled" value="-1"〉
〈param name="DropTarget" value="0"〉
〈param name="HelpFile" value〉
〈param name="DoubleBuffered" value="0"〉
〈param name="Enabled" value="-1"〉
〈param name="Cursor" value="0"〉
〈param name="HelpType" value="1"〉
〈param name="HelpKeyword" value〉
〈/object〉 請問如果程式中不使用這些屬性,通過DELPHI的VIEW->Type Library 介面將它們刪除,會影響其工作嗎?
同樣,DELPHI的ActiveForm也自帶了如下事件,如果刪除,會影響其工作嗎? OnActivate, OnClick, OnCreate, OnDblClick, OnDestroy, OnDeactivate, OnKeyPress, OnPaint. 問題二:
在定義屬性和事件時,通過DELPHI的VIEW->Type Library 介面查看,Flag中有許多選項: Replaceable,DisplayBindable,NonBrowsable,Restricted,DefaultBindable,ImmediateBindable,Source,Hidden,Uses Get Last Error,Bindable,Default Collection Element,Request Edit,UI default. 這些選項的作用分別是什麼?同樣,某個Interface也有許多Flag選項: Hidden,Preddefined,NonExtensible,Can Create,Control,Replaceable,Application Object,Dual,Aggregatable,Licensed,OleAutomation. 這些Flag選項的作用又是什麼?
|
yzml
一般會員 ![]() ![]() 發表:4 回覆:4 積分:1 註冊:2004-12-26 發送簡訊給我 |
問題三:
HTML向ActiveX控制項傳送參數有以下幾種方式: (1)載入時通過Param傳入:
〈object classid="clsid:xxxx-xxxx-xxxx-xxxx-xxxx" id="ActiveX1" width="594" height="401"〉
〈param name="Visible" value="0"〉
〈/object〉 (2)載入後通過函數傳出、傳入: 〈object classid="clsid:xxxx-xxxx-xxxx-xxxx-xxxx" id="ActiveX1" width="594" height="401"〉 傳入 ActiveX1.Visible=0
傳出 CanBeSee=ActiveX1.Visible 在關於DELPHI的有關資料中有多種方式實現參數傳送:
(1)在Type Library的pas檔中定義:
IYzFTP = interface(IDispatch)
['{D0B55322-B569-4A7E-B256-AEB5B1EC2828}']
function Get_ServerName: WideString; safecall;
procedure Set_ServerName(const Value: WideString); safecall;
property ServerName: WideString read Get_ServerName write Set_ServerName;
在impl的pas檔中定義:
type
TYzFTP = class(TActiveForm, IYzFTP)
……
protected
function Get_ServerName: WideString; safecall;
procedure Set_ServerName( Value:WideString); safecall;
…….
end; implementation
……
function TYzFTP.Get_ServerName: WideString;
begin
Result := WideString(ServerName);
end; procedure TYzFTP.Set_ServerName(const Value: WideString);
begin
ServerName := Value;
end;
(2)在Type Library的pas檔中定義:
TYzFTP = class(TOleControl)
……
published
property ServerName: WideString index 201 read GetWideStringProp write SetWideStringProp stored False;
……
end; 但GetWideStringProp、SetWideStringProp是幹什麼用的?應該如何實現?與Get_ServerName和Set_ServerName是什麼關係? (3)在Impl的pas檔中定義,如:
TActiveFormNewX = class(TActiveFormX,IPersistPropertyBag)
public
ServerName:String;
protected
function IPersistPropertyBag.Load =PersistPropertyBagLoad;
end; function TActiveFormNewX.PersistPropertyBagLoad(const pPropBag:IPropertyBag;
Const pErrorLog:IErrorLog):HResult;stdCall;
var
Str:OleVariant;
begin
if pPropBag.Read('ServerName', Str ,pErrorLog) = S_OK then
ServerName :=Str;
Result:=S_OK;
end;
請問這幾種方法的關係、適用場合?如何為某些屬性分配預設值,既既不通過〈param name='XXXX' value='YYYY' 〉也不通過ActiveX1.XXX=YYY 給屬性XXX賦值時,XXX有個原始的預設值?
|
yzml
一般會員 ![]() ![]() 發表:4 回覆:4 積分:1 註冊:2004-12-26 發送簡訊給我 |
問題四:
我增加了屬性ServerName和事件OnTestEnd,但編譯時出錯,明明這屬性和事件在Type Library中已經定義,為什麼還出錯呢?該如何修改? =============================================================
YzFTPImpl.pas
=============================================================
unit YzFTPImpl; {$WARN SYMBOL_PLATFORM OFF} interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ActiveX, AxCtrls, YzFTP_TLB, StdVcl; type
TYzFTP = class(TActiveForm, IYzFTP)
private
{ Private declarations } FEvents: IYzFTPEvents;
procedure TestEndEvent(Sender: TObject); protected
{ Protected declarations }
procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
procedure EventSinkChanged(const EventSink: IUnknown); override; function Get_ServerName: WideString; safecall;
procedure Set_ServerName(const Value:WideString); safecall;
public
{ Public declarations }
procedure Initialize; override; end; implementation uses ComObj, ComServ; {$R *.DFM} { TYzFTP } procedure TYzFTP.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_YzFTPPage); }
end; procedure TYzFTP.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as IYzFTPEvents;
inherited EventSinkChanged(EventSink);
end; procedure TYzFTP.Initialize;
begin
inherited Initialize;
OnTestEnd := TestEndEvent;
end; function TYzFTP.Get_ServerName: WideString;
begin
Result := WideString(ServerName);
end; procedure TYzFTP.TestEndEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnTestEnd;
end; procedure TYzFTP.Set_ServerName(const Value: WideString);
begin
ServerName := Value;
end; initialization
TActiveFormFactory.Create(
ComServer,
TActiveFormControl,
TYzFTP,
Class_YzFTP,
1,
'',
OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
tmApartment);
end.
==============================================================
Error.TXT
==============================================================
Build
[Error] YzFTPImpl.pas(x1x): Undeclared identifier: 'OnTestEnd'
[Error] YzFTPImpl.pas(x2x): Not enough actual parameters
[Error] YzFTPImpl.pas(x3x): Undeclared identifier: 'ServerName'
[Error] YzFTPImpl.pas(x4x): Undeclared identifier: 'ServerName'
[Fatal Error] YzFTP.dpr(6): Could not compile used unit 'YzFTPImpl.pas'
|
Ktop_Robot
站務副站長 ![]() ![]() 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |