Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with TOleContainer 1

Status
Not open for further replies.

Vovin

Programmer
Aug 24, 2003
63
GB
Hi,

can anyone help with this? I'm trying to write some code in a button event handler. When a user clicks the button they are asked to select a file. This file then should be displayed in the TOleContainer object on my form.

At the moment all I'm getting in the TOleContainer is the name of the file. If you double click the file name however the application associated with the file is launched and the file is displayed. How can I get the file to display on my form though.

Here is my code:

procedure TForm1.Button1Click(Sender: TObject);
var
filename : string;
CreateInfo : TCreateInfo;
begin
if OpenDialog1.Execute then
begin
filename := OpenDialog1.FileName;
FillChar(CreateInfo, sizeOf(TCreateInfo), 0);

CreateInfo.CreateType := ctFromFile;
CreateInfo.ShowAsIcon := false;
CreateInfo.FileName := filename;
OleContainer1.CreateObjectFromInfo (CreateInfo);
end;
end;

Any help with this would be very much appreciated. Thanks in advance.
 
fiddled around with olecontainer and this works like a charm :

Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
 OleContainer1.CreateObjectFromFile('c:\temp\test.xls',false);
end;

hope this helps

--------------------------------------
What You See Is What You Get
 
Thanks whosrdaddy,

I tried your line of code. I couldn't test it using an excel file as I don't have office installed but I tried using it with a .bmp file and it worked fine. It didn't work with .jpg, .txt, or .pdf however. Do you know if there is any way to display these file types in the TOleContainer?
 
as with all OLE objects, there must be a registered OLE server to handle the file. so you must install an application that handles these file formats and also has OLE support.(acrobat reader for PDF, office for XLS, and so on). That's the nice thing about OLE, your application doesn't know squat about the file it is displaying since this handled through the OLE server COM object.



--------------------------------------
What You See Is What You Get
 
I have Adobe Acrobat installed on my machine so I'm suprised that pdf's are not displayed in the TOleContainer.

If I right click on the TOleContainer component and select 'Insert Object' then I get a list of object types that I presume are supported (pdf's are there).

 
that is weird,

if have acrobat reader 6 onto my Laptop and it doesn't appear on the 'Insert Object list.this must mean that Acrobat reader doesn't have the old OLE implementation anymore. You can control a PDF document via normal ActiveX COM object.

--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top