OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Delphi problems w/ storeToURL and storeAsURL

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Tue Jul 27, 2004 5:58 am    Post subject: Delphi problems w/ storeToURL and storeAsURL Reply with quote

This thread continued from....
http://www.oooforum.org/forum/viewtopic.php?p=43196#43196

Both storeToURL() and storeAsURL() methods are well documented. They are part of the XStorable interface.

You cannot just make up method names. There is no ExportToUrl function. You can even look in the index under E, and no ExportToURL.

Here is how I find these methods. Start at a DrawingDocument. Notice that the DrawingDocument includes the service OfficeDocument. So anything that an OfficeDocument has, is also part of a DrawingDocument.

The OfficeDocument has an interface called XStorable, and additional interfaces. (Therefore, by the previous paragraph, these interfaces of an OfficeDocument are also part of any DrawingDocument.)

The XStorable interface is where you find the methods storeToURL() and storeAsURL().

The use of storeToURL() and storeAsURL() are well understood and commonly used. Have you tried your example in OOo Basic to see that it works? The way your are using these methods appears to be correct.

Are you confident that your MakePropertyValue function is returning the correct thing?

I remember the first time I wanted to call storeToURL() to save a PDF from some Visual FoxPro code. I couldn't see why it wasn't working. In the end it was some problem with VFP and COM that I had to understand how to work around. But I did get it to work.

Here are some things I've written in the past about how to navigate the API documentation. I use the API docs as my primary reference. I use the extremely helpful Xray tool (which I download from OOoMacros.org) to get a peek into the actual implementation. But I program to the published API.


How to navigate the OOo API Docs
================================

In this post, begin at the sentence...
"So how did I learn about how to use removeByIndex() ?"
http://www.oooforum.org/forum/viewtopic.php?p=25537#25537

http://www.oooforum.org/forum/viewtopic.php?p=29989#29989
http://www.oooforum.org/forum/viewtopic.php?p=13511#13511
http://www.oooforum.org/forum/viewtopic.php?p=15399#15399
http://www.oooforum.org/forum/viewtopic.php?p=15246#15246
http://www.oooforum.org/forum/viewtopic.php?p=11995#11995
http://www.oooforum.org/forum/viewtopic.php?t=3479
http://www.oooforum.org/forum/viewtopic.php?p=16186#16186
http://www.oooforum.org/forum/viewtopic.php?t=4608
http://www.oooforum.org/forum/viewtopic.php?p=13834#13834
http://www.oooforum.org/forum/viewtopic.php?p=15034#15034
http://www.oooforum.org/forum/viewtopic.php?t=3735
http://www.oooforum.org/forum/viewtopic.php?t=3681

XShapes, DrawPage, GenericDrawPage
http://www.oooforum.org/forum/viewtopic.php?t=5328

Developer's Guide
http://api.openoffice.org/DevelopersGuide/DevelopersGuide.html

(Developer's Guide TOC is here)
http://api.openoffice.org/docs/DevelopersGuide/DevelopersGuide.htm

and the online API reference....
http://api.openoffice.org/docs/common/ref/com/sun/star/module-ix.html

Useful links from Russ...
http://www.oooforum.org/forum/viewtopic.php?p=16374#16374
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
pasha_golub
General User
General User


Joined: 29 Jun 2004
Posts: 24
Location: Ukraine

PostPosted: Tue Jul 27, 2004 11:10 pm    Post subject: Reply with quote

Thanks for all. I need some time to check all possible missunderstandings. Any way, I'll post result of my research Smile in this thread. Thanks again.
_________________
Nullus est in vitae sensus, ipsa vera est sensus!
Back to top
View user's profile Send private message
pasha_golub
General User
General User


Joined: 29 Jun 2004
Posts: 24
Location: Ukraine

PostPosted: Wed Jul 28, 2004 6:15 pm    Post subject: Reply with quote

Well, I decide to test this code in VBA.

So we have:
Code:
Sub OO()
Dim objServiceManager As Object
Dim objDesktop As Object
Dim args(0) As Object
Dim Doc As Object
Dim oStruct As Object

Set objServiceManager = CreateObject("com.sun.star.ServiceManager")
Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
Set Doc = objDesktop.loadComponentFromURL("private:factory/sdraw", "_blank", 0, args)

Dim DrawPage As Object
Set DrawPage = Doc.getDrawPages.getByIndex(0)

Dim Ellipse As Object
Set Ellipse = Doc.createInstance("com.sun.star.drawing.EllipseShape")

Set oStruct = objServiceManager.Bridge_GetStruct("com.sun.star.awt.Point")
oStruct.x = 1000
oStruct.y = 2000
Ellipse.Position = oStruct

Set oStruct = objServiceManager.Bridge_GetStruct("com.sun.star.awt.Size")
oStruct.width = 1000
oStruct.height = 2000
Ellipse.Size = oStruct

Ellipse.FillStyle = 1 'Solid
Ellipse.FillColor = hFF0000

Call DrawPage.Add(Ellipse)

Set oStruct = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oStruct.Name = "FilterName"
oStruct.Value = "BMP - MS Windows"

Set args(0) = oStruct

Call Doc.storeAsUrl("file:///C:/Test.bmp", args())

Call objDesktop.terminate
End Sub


But in this case at line with StoreAsUrl I have Runtime error 1001: 'com.sun.star.io.IOException'.

I'm absolutely confused and even don't know what to do. I checked this code many times comparing samples on this forum and mine.

Please tell me what's wrong? Shocked
_________________
Nullus est in vitae sensus, ipsa vera est sensus!
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Aug 02, 2004 10:27 am    Post subject: Reply with quote

Using VB (man what a pain!) I get these results....

I can replace this line
Code:
Call Doc.storeToUrl("file:///C:/Test.bmp", args())

with this line
Code:
Call Doc.storeToUrl("file:///C:/Test.sxd", Array())

and the program saves a native SXD file just fine.

So the problem must be the filters.

I check the list of available filters, and I see that the one I should be using is....

Code:
oStruct.Value = "draw_bmp_Export"


Finally, note that when saving the BMP, I use storeToURL instead of storeAsURL.



Import Export Filters list
==========================
http://www.oooforum.org/forum/viewtopic.php?t=3549
http://www.oooforum.org/forum/viewtopic.php?p=15416#15416

http://framework.openoffice.org/files/documents/25/897/filter_description.html

http://www.oooforum.org/forum/viewtopic.php?t=3545
http://www.oooforum.org/forum/viewtopic.php?t=3175
http://www.oooforum.org/forum/viewtopic.php?p=10311#10311

No documentation on filter options
http://www.oooforum.org/forum/viewtopic.php?t=2735
http://www.oooforum.org/forum/viewtopic.php?t=3458
http://www.oooforum.org/forum/viewtopic.php?t=5565
Some possible insight to filter options
http://www.oooforum.org/forum/viewtopic.php?t=6769
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
pasha_golub
General User
General User


Joined: 29 Jun 2004
Posts: 24
Location: Ukraine

PostPosted: Tue Aug 03, 2004 12:35 am    Post subject: Reply with quote

Oh, now I see the problem - there are another export filters. Laughing

As I said before I look for way to save drawing in not native format, but the only thing that I found was idea that there is another way for exporting drawings. I was thinking that some ExportTo... method must exists.

As it was found out (by you Very Happy ) I must use another filter names only. Thanks a lot.
_________________
Nullus est in vitae sensus, ipsa vera est sensus!
Back to top
View user's profile Send private message
pasha_golub
General User
General User


Joined: 29 Jun 2004
Posts: 24
Location: Ukraine

PostPosted: Thu Aug 05, 2004 3:10 am    Post subject: Reply with quote

Well, hi. It's me again. Smile

I solved this problem for VB script, like this:
Code:

Sub OO()
Dim objServiceManager As Object
Dim objDesktop As Object
Dim args(0) As Object
Dim Doc As Object
Dim oStruct As Object

Set objServiceManager = CreateObject("com.sun.star.ServiceManager")
Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
Set Doc = objDesktop.loadComponentFromURL("private:factory/sdraw", "_blank", 0, args)

Dim DrawPage As Object
Set DrawPage = Doc.getDrawPages.getByIndex(0)

Dim Ellipse As Object
Set Ellipse = Doc.createInstance("com.sun.star.drawing.EllipseShape")

Set oStruct = objServiceManager.Bridge_GetStruct("com.sun.star.awt.Point")
oStruct.x = 1000
oStruct.y = 2000
Ellipse.Position = oStruct

Set oStruct = objServiceManager.Bridge_GetStruct("com.sun.star.awt.Size")
oStruct.width = 1000
oStruct.height = 2000
Ellipse.Size = oStruct

Ellipse.FillStyle = 1 'Solid
Ellipse.FillColor = hFF0000

Call DrawPage.Add(Ellipse)

Set oStruct = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oStruct.Name = "FilterName"
oStruct.Value = "draw_bmp_Export"

Set args(0) = oStruct

Call Doc.storeToUrl("file:///C:/Test.bmp", args())

Call objDesktop.terminate
End Sub


Works just fine. But I can't do the same in Delphi. I am sick and tired of this. Anybody, please help Smile
Code:

var
  Form1: TForm1;
  StarOffice, StarDesktop, DrawDoc, DrawPage: Variant;
implementation

{$R *.dfm}


function MakePoint(const X, Y: integer):variant;
var Struct: variant;
begin
    Struct := StarOffice.Bridge_GetStruct('com.sun.star.awt.Point');
    Struct.X := X;
    Struct.Y := Y;
    Result := Struct;
end;

function MakeSize(const Width, Height: integer):variant;
var Struct: variant;
begin
    Struct := StarOffice.Bridge_GetStruct('com.sun.star.awt.Size');
    Struct.Width := Width;
    Struct.Height := Height;
    Result := Struct;
end;

function Connect: boolean;
begin
   if VarIsEmpty(StarOffice) then
      StarOffice := CreateOleObject('com.sun.star.ServiceManager');
   StarDesktop := StarOffice.createInstance('com.sun.star.frame.Desktop');
   Result := not (VarIsEmpty(StarOffice) or VarIsNull(StarOffice));
end;

function CreateDrawDocument: boolean;
begin
 DrawDoc := StarDesktop.loadComponentFromURL( 'private:factory/sdraw', '_blank',
   0, VarArrayCreate([0,-1],varVariant));
 Result := not (VarIsEmpty(DrawDoc) or VarIsNull(DrawDoc));
 DrawPage := DrawDoc.getDrawPages.getByIndex(0);
end;

function DrawRectangle(const X,Y,Width,Height: integer):variant;
begin
   Result := DrawDoc.createInstance('com.sun.star.drawing.RectangleShape');
   Result.Position := MakePoint(X,Y);
   Result.Size := MakeSize(Width,Height);
   DrawPage.Add(Result);
end;

function DrawEllipse(const X,Y,Width,Height: integer):variant;
begin
   Result := DrawDoc.createInstance('com.sun.star.drawing.EllipseShape');
   Result.Position := MakePoint(X,Y);
   Result.Size := MakeSize(Width,Height);
   DrawPage.Add(Result);
end;

function DrawTextShape(const X,Y,Width,Height: integer):variant;
begin
   Result := DrawDoc.createInstance('com.sun.star.drawing.TextShape');
   Result.Position := MakePoint(X,Y);
   Result.Size := MakeSize(Width,Height);
   DrawPage.Add(Result);
end;

{ Fill styles:
NONE     the area is not filled.
SOLID    use a solid color to fill the area.
GRADIENT    use a gradient color to fill the area.
HATCH    use a hatch to fill the area.
BITMAP     use a bitmap to fill the area.}

const
OOfsNone = 0;
OOfsSolid = 1;
OOfsGradient = 2;
OOfsHatch = 3;
OOfsBitmap = 4;

{ Line styles:
NONE     the line is hidden.
SOLID    the line is solid.
DASH    the line use dashes.}

const
OOlsNone = 0;
OOlsSolid = 1;
OOlsDash = 2;

{ Circle kinds:
FULL     a full circle
SECTION    a circle with a cut connected by a line
CUT    a circle with a cut connected by two lines
ARC    a circle with an open cut
}

const
OOckFull = 0;
OOckSection = 1;
OOckCut = 2;
OOckArc = 3;

procedure DrawSimplePieChart;
var Circle1, Square1, Text1: Variant;
begin

   Circle1 := DrawEllipse(8000, 10000, 5000, 5000);
   Circle1.LineStyle := OOlsSolid;
   Circle1.LineWidth := 10;
   Circle1.FillStyle := OOfsSolid;
   Circle1.FillColor := $FF0000; //RGB notation
   Circle1.CircleKind := OOckSection;
   Circle1.CircleStartAngle := 0;
   Circle1.CircleEndAngle := 1000;

   Circle1 := DrawEllipse(8000, 10000, 5000, 5000);
   Circle1.LineStyle := OOlsSolid;
   Circle1.LineWidth := 10;
   Circle1.FillStyle := OOfsSolid;
   Circle1.FillColor := $0000FF; //RGB notation
   Circle1.CircleKind := OOckSection;
   Circle1.CircleStartAngle := 1000;
   Circle1.CircleEndAngle := 36000;


   Square1 := DrawRectangle(8000, 16000, 500, 500);
   Square1.LineStyle := OOlsSolid;
   Square1.LineWidth := 10;
   Square1.FillStyle := OOfsSolid;
   Square1.FillColor := $FF0000;


   Square1 := DrawRectangle(8000, 17000, 500, 500);
   Square1.LineStyle := OOlsSolid;
   Square1.LineWidth := 10;
   Square1.FillStyle := OOfsSolid;
   Square1.FillColor := $0000FF;

   Text1 := DrawTextShape(9000, 16000, 8000, 500);
   Text1.LineStyle := OOlsNone;
   Text1.FillStyle := OOfsNone;
   Text1.Text.setString('SCO True statements');

   Text1 := DrawTextShape(9000, 17000, 8000, 500);
   Text1.LineStyle := 0;
   Text1.FillStyle := 0;
   Text1.Text.setString('SCO False statements');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if Connect then
    if CreateDrawDocument then
     begin
      Button2.Enabled := True;
      DrawSimplePieChart;
     end
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  StarDesktop.Terminate;
  StarDesktop := UnAssigned;
  StarOffice := UnAssigned;
end;


{$D+} {$L+}

function TForm1.MakePropertyValue(PropName:string; PropValue:variant):variant;
var Struct: variant;
begin
  Struct := StarOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
  Struct.Name := PropName;
  Struct.Value := PropValue;
  Result := Struct;
end;


procedure TForm1.Button3Click(Sender: TObject);
var VariantArr: variant;
begin
    VariantArr := VarArrayCreate([0, 0], varVariant);
    VariantArr[0] := MakePropertyValue('FilterName', 'draw_bmp_Export');
    DrawDoc.StoreToURL('file:///c:/sco.bmp', VariantArr);
end;

end.


Produced file is not BMP valid file. But it may be opened by OOo. It seems to me that it was saved in native *.sxd format. Thus problem is in MakeProperty function. But this function work fine in another application. Crying or Very sad
_________________
Nullus est in vitae sensus, ipsa vera est sensus!
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3618
Location: Columbus, Ohio, USA

PostPosted: Thu Aug 05, 2004 7:35 am    Post subject: Reply with quote

It looks to me like you use the correct name. I have not created a test case for this, but have you tried inspecting the returned argument array to make certain that it contains what you expect?
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group