Transformation of Exe Engineering and OCX Project (2002530 Triple Gold Copyright)

zhaozj2021-02-11  182

Transformation of Exe Engineering and OCX Project (2002/5/30 Triple Gold Copyright)

1 from EXE to OCX project

Such transformation has a commonly used method that can talk more stupid, all of the Exe project master Form

Elements and their event handler are copied. Although this method is stable, but troublesome. Easy to let

Head is big. Here we focus on a relatively quick solution, through the inheritance of the class, transformation. Summary

Including, it is to directly use the master form of the EXE project as the main form of the OCX project, and put its parent class by TFORM.

Change to TACTIVEFORM. The details are described in detail.

(1) Preparing

Before starting, all files of the EXE project are best to copy all the documents of the EXE project such as .pas, .dfm (project .dpr, etc.)

A new directory. If you don't want to do this, you can also save the OCX project to the same directory, but don't

Exe project reintegration to avoid overlay. Generate an ActiveForm (note: This keeps blank, don't go to it

Place any components, in order to facilitate explanation, set its name to ActiveFormX, the unit file is

ActiveFormx.PAS while saving OCX projects. Suppose the original master form's Name is frmmain, unit file

For MainForm.PAS.

(2) Change inheritance relationship

Open Mainform.Pas, find the declaration of the TFRMMAIN class: TFRMMAIN = Class (TFORM)

Change to TfrmMain = Class (TactiveFormX)

(3) Put frmmain as the main form of the project

Open ActiveFormx.Pas, find the Initialization section, as shown below:

INITIALIZATION

TactiveFormFactory.create

COMSERVER,

TactiveformControl,

TactiveFormx,

Class_ActiveFormX,

1,

'',

OLEMISC_SIMPLEFRAME OLEMISC_ACTSLIKELABEL,

TMAPARTMENT);

Change the TACTIVEFORMX in the fifth line to TFRMMain, so that OCX project's master FORM has become the original EXE project.

Main Form, TFrmMain.

(4) Attribute declaration

Check out the Delphi source code, you can see the following inheritance chain:

Tcustomform-> Tcustomactiveform-> TACTIVEFORM

Tcustomform-> TFORM

TForm's part of the Published property is not declared in TactiveForm, and these attributes exist in their common parent.

Class TCUSTOMFORM and in the Public section. So, if you change frmmain in the properties editor

These properties, Delphi will press TACTIVEFORMX-> TCUSTomactiveform-> TCUSTOMACTIVEFORM-> TCustomform

The sequence is found in the Publish section and sets these properties, and these three parent Published portions do not include these genus

Sex. In this way, Delphi will prompt the address error. So, as long as these properties are declared in TactiveFormX, the problem

It can be solved. The event attribute at the beginning of the ON is also the same. Open ActiveFormX.PAS, copy the following code

The declaration part of TactiveFormX can be.

Published

Property Action;

Property Align;

Property Alphablend Default False DEFAULT FALSE

Property AlphablendValue Default 255;

Property Bidimode;

Property bordericons;

Property Borderstyle;

Property clientHeight; Property ClientWidth;

Property TransparentColor Default False DEFAULT FALSE

Property TransparentColorValue Default 0;

Property CTL3D;

Property USEDOCKManager;

Property DefaultMonitor;

Property Docksite;

Property Dragkind;

Property Dragmode;

Property enabled;

Property ParentFont Default False;

Property Formstyle;

Property helpfile;

Property icon;

Property Menu;

Property ObjectMenuItem

Property Parentbidimode;

Property Position;

Property visible;

Property WindowState;

Property WINDOWMENU;

Property oncanResize;

Property OnClose;

Property OnClosequery;

Property OnConstrainedResize;

Property OnDockDrop;

Property OnDockOver;

Property OneundDock;

Property OngetsiteInfo;

Property Onhide;

Property onhelp;

Property OnMousewheel;

Property OnMousewheeldown;

Property OnMousewheelup;

Property OnResize;

Property onshortcut;

Property OnShow;

Property onstartdock;

Property Onundock;

For the event properties listed above, it doesn't have to be declared. FRMMAIN has a declaration of handlers

okay.

(5) Change event connection

If you write code in the TFrmMain on the onpaint event, you can find that these code will not be executed.

of. What is the reason? Open ActiveFormx.PAS, find TactiveFormX's initialize process, you can send

Now the following code:

Inherited Initialize;

OnActivate: = ActivateEvent;

Onclick: = ClickEvent;

Oncreate: = CREATEEVENT;

Ondblclick: = dblclickevent;

ONDEACTIVATE: = deActivateEvent;

ONDESTROY: = destroyevent;

ONKEYPRESS: = keypressEvent;

Onpaint: = paintevent;

The original problem is here, the onpaint event is eaten by Delphi and is changed to execute Paintevent. How do you do it?

Comment out the second line, then write a process of your own onpaint event, don't forget the parameter sender.

Such as: procedure mypaint (sender: TOBJECT);

Then I will be paid to ONPAIN in the TFrmMain's oncreat event. ONPAINT: = MyPaint;

Several events listed above are similar to ONPAINT. Imitate OnPaint is OK.

2 from OCX to EXE project

(1) OCX engineering framework

In summary, the OCX project is best not to use ActiveForm as the master Form, and additionally generate a normal form as the master Form, and then processes the method described above. The other data operation Form is also ordinary form.

Calling by the master Form.

(2) Transform to EXE project

As long as you do it according to (1), the problem is very good. Generate an ordinary engineering and put OCX project in addition to Activeform

All FORMs exported to all forms.

OK, get it!

Better more articles in the three gold homepage - Tian Mingxin Tree

http://vip.6to23.com/tianmingxin

转载请注明原文地址:https://www.9cbs.com/read-4403.html

New Post(0)