activex and form accsess error

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

activex and form accsess error

Mesaj gönderen mia »

why in ActiveX i cannot access the main form instance from other form , here is my project that working normal in vcl but when moved to activex its stop from working , project goal is set image element from tembededwb in mainform 2 to edit1 box in main form1 here is the project in attachment code work normal in vcl but in activex its not . also i cannot accsess any of the form instance in activex from another form
Dosya ekleri
embeddedactivex.zip
(66.05 KiB) 79 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

help guys :(
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: activex and form accsess error

Mesaj gönderen mrmarman »

Hi.

This forum members usually likes to answer question(s). :D

I think nobody understands what you want to do in your project, or they don't realize how to embed the ActiveX form to any Delphi project.

I try to create a simple example for you and/or forum members whom interested in this issue.

Now, your question was why cannot access activex mainform from sub forms.
The answer is, ActiveX forms class works over "Shell Embedding" class. First I show you how to know this, then I give you the solution...

I recommend you to use a tool named "SPY&CAPTURE"
( added to this message attachment )
Spy & Capure Version 2.70 yazdı:Spy & Capture is a spying tool for Windows 9x/NT.
It uses direct mouse positioning to get window properties and all it's
objects, styles, classes and process information.
Resim

If you want multiform with ActiveX and so want to give the all forms controls between to the other forms then must carry all master ActiveXForm controls on to the on of them.

You think about like this: an activex control like a DPR file. The forms are the forms. if you want a form controls other form components, then you can do between forms. Because they are the same Active Control area.
Resim
Dosya ekleri
ActiveX_MultiForm_Test.rar
TEST Project
(252.66 KiB) 94 kere indirildi
Spy.rar
Spy & Capure Version 2.70
Spy & Capture is a spying tool for Windows 9x/NT.
It uses direct mouse positioning to get window properties and all it's
objects, styles, classes and process information.
(241.5 KiB) 89 kere indirildi
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

i able to show forms from the main unit form ,, but i cannot set from other form to the main unit form as example in your project your main unit is ActiveFormImpl and this is the main unit class , list assume that there is Tedit included to the class

Kod: Tümünü seç

 TActiveFormX = class(TActiveForm, IActiveFormX)
    Edit1:Tedit;// tedit control
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
and in your form2 lets say i want to add some text to edit1 in ActiveFormImpl as example

Kod: Tümünü seç

type
  TForm2 = class(TForm)
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses ActiveFormImpl;

{$R *.dfm}

procedure TForm2.BitBtn1Click(Sender: TObject);
var
text:string;
begin
text := 'mrmarman';
 ActiveFormImpl.edit1.text := text;

end;

end.
what i mean i can normally set what ever i want from form2 or form3 or form4 etc.. but i cannot set any thing as example from form2 to main unit ActiveFormImpl TActiveFormX
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: activex and form accsess error

Mesaj gönderen mrmarman »

In this case you need to manually add new event to ActiveX side to collect data.

I can show you with screen capture video. Because this is a litle bit tricky to describe... :roll:


ActiveX Side
Resim
Delphi Side
Resim

This is the project source..
Dosya ekleri
ActiveX_ReturnValue_ActiveXFormToDelphiSide.rar
ActiveX to Delphi Side Value Transfer
(246.71 KiB) 65 kere indirildi
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

thats far away from the point that i want to achieve mrmarman , did you download my attachment ? i just wanted to set form instance in activex it self i will not use type liberary in standlone exe , if you see my project you will get my point here is the project code for better understand

main form code

Kod: Tümünü seç

unit main1;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ActiveX, AxCtrls, embed_TLB, StdVcl, Vcl.StdCtrls;

type
  Tform1 = class(TForm, Iform1)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }


  protected
    { Protected declarations }

  public
    { Public declarations }
     procedure setimg(Image:string);
    procedure imgSet(img:string);
    procedure showEmo(L,T:Integer);

  end;

  var
  Form1 : Tform1;

implementation

uses ComObj, ComServ, main2;

{$R *.DFM}

{ Tform1 }

  procedure Tform1.setimg(image: string);
begin
  imgSet(image);
end;


procedure Tform1.imgSet(img: string);
begin
  with self.edit1 do
  begin
    Text := Text + img;
    SelStart := length(Text);
    if self.Visible then SetFocus;
    SelLength := 0;
  end;
end;

procedure Tform1.Button1Click(Sender: TObject);
var
  Rect: TRect;
begin
  GetWindowRect(Self.button1.Handle, Rect);
  showEmo(Rect.Left + 70,(Rect.Top - 290));
end;

procedure TForm1.showEmo(L,T:Integer);
 var
    Rect: TRect;
  begin
    try
      GetWindowRect(button1.Handle, Rect);
      if not Assigned(Form2) then
      begin
        Form2 := TForm2.CreateParented(0);
        form2.FormStyle := fsStayOnTop;
      end;
      Form2.Left := L; // Rect.Left;
      Form2.top := T; // Rect.Top - emo.Height;
    finally
      form2.Visible := not(form2.Visible);
    end;

  end;



initialization
  TActiveFormFactory.Create(
    ComServer,
    TActiveFormControl,
    Tform1,
    Class_form1,
    0,
    '',
    OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
    tmApartment);
end.
second form code

Kod: Tümünü seç

unit main2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, SHDocVw_EWB, EwbCore,
  EmbeddedWB, MSHTML_EWB, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    ewbpage: TEmbeddedWB;
    load: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure ewbpageBeforeNavigate2(ASender: TObject; const pDisp: IDispatch;
      var URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
      var Cancel: WordBool);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses main1;

{$R *.dfm}

procedure TForm2.ewbpageBeforeNavigate2(ASender: TObject; const pDisp: IDispatch;
  var URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
  var Cancel: WordBool);
  var
  MousePos: TPoint;
  HtmlElement: IHTMLElement;
  iHTMLDoc: IHtmlDocument2;
begin
if Pos('#sm',URL)>0 then
begin
  if Supports(ewbpage.Document, IHtmlDocument2, iHTMLDoc) then
  begin
    if GetCursorPos(MousePos) then
    begin
      MousePos := ewbpage.ScreenToClient(MousePos);
      HtmlElement := iHTMLDoc.ElementFromPoint(MousePos.X, MousePos.Y);
      if Assigned(HtmlElement) then
      showmessage(HtmlElement.getAttribute('id', 0));
      if form1 <> nil then form1.setimg(HtmlElement.getAttribute('id', 0));
      Cancel := True;
      Self.Close;
    end;
  end;
end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
ewbpage.LoadFromStrings(load.Lines);
end;

end.
you can see here at this line

Kod: Tümünü seç

      showmessage(HtmlElement.getAttribute('id', 0)); //its already read the element 
      if form1 <> nil then form1.setimg(HtmlElement.getAttribute('id', 0))// but cannot set  tedit in form1
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: activex and form accsess error

Mesaj gönderen mrmarman »

Please try this... (project source attached the message)

- I think you steered me to the wrong way with second message, because I allready answered your question above.
- I tought that you need this variable on Delphi side, but you are asking all off these the same ActiveX Control side...

- Other way, I cannot understand your problem, I'm sorry.
- This is what I said that message. I created a third form and moved the master (activex) form contents to it.

Resim
Dosya ekleri
embeddedactivex.rar
Updated project
(72.28 KiB) 67 kere indirildi
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

thank you mrmarman so i dont have to make my main form as first created ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: activex and form accsess error

Mesaj gönderen mrmarman »

Yes you're right. In this case, the main form only a coordinator form. Other forms are the working areas.

Are you satisfy with this solution ?
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

some how yes but there is stuff coming to my mind tell me thats gonna have pitfalls like if i added read and write property to be able to read it by html params that will be allowed in the second form ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: activex and form accsess error

Mesaj gönderen mrmarman »

So, then you'll see in time. I believe that you will handle that.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

i will give a try and will come back with feedback thank you very much mrmarman for the great help
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

what i expect is happend cannot set property to the second form shows always empty and the second form opened in new webpage :( i dont know what to do

property that i made

Kod: Tümünü seç

 function Get_name: WideString; safecall;
    procedure Set_name(const Value: WideString); safecall;
    function Get_tell: WideString; safecall;
    procedure Set_tell(const Value: WideString); safecall;
    function Get_Server: WideString; safecall;
    procedure Set_Server(const Value: WideString); safecall;
procedure and form show event

Kod: Tümünü seç

function Tmainform1.Get_name: WideString;
begin
 Result := mainform2.Name;
end;

procedure Tmainform1.Set_name(const Value: WideString);
begin
mainform2.Name := Value;
end;

function Tmainform1.Get_tell: WideString;
begin
 Result := mainform2.tell;
end;

procedure Tmainform1.Set_tell(const Value: WideString);
begin
mainform2.tell:= Value
end;

procedure Tmainform1.FormShow(Sender: TObject);
begin
  Application.CreateForm( Tmainform2, mainform2);
  mainform2.Show;
end;

function Tmainform1.Get_Server: WideString;
begin

end;

procedure Tmainform1.Set_Server(const Value: WideString);
begin

end;
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: activex and form accsess error

Mesaj gönderen mrmarman »

- Tmainform1 is ActiveX main form isn't it ?
- What do you expected with this property design ?

- Form2 and Form3 can communicate between them, but tmainform is ActiveX control. If you pass some value to the delphi side then we try other things to do for it. But if it not most necessary thing, choose the easiest way.

- I wonder why do you working over ActiveX controls ? It takes more time against native delphi project.
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: activex and form accsess error

Mesaj gönderen mia »

i already finish a native delphi project and i try to transform it to activex , reason is for education purpose i been working on this project for about year and also i just finish my university and try to work over my mind and collect information as much as i can , thats why its comes to activex now to know about how its works deeply , and yes Tmainform1 is the activex main form and it has the property that must be passing by html params and i want to read there values and pass it to form 2 or even to a unit as getter and setter and use them later i know that iam too much noise but you are my only savior
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Cevapla