Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 21.05.10 06:50 
Hi, Delpher,
ich versuche, eine Instanz von OpenOffice ähnlich wie Word einzubinden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
function tBuchMain.Word_vorhanden: boolean;
begin
  Word_vorhanden := false;
  try
    MSWord := CreateOleObject('Word.Application');
    Word_vorhanden := true;
  except
    ShowMessage('Word kann nicht gestartet werden!');
    Word1.enabled := false;
    Exit;
  end;
end;

function tBuchMain.OoffWriter_vorhanden: boolean;
begin
  OoffWriter_vorhanden := false;
  try
    OoffWri := CreateOleObject('Writer.Application');
    OoffWriter_vorhanden := true;
  except
    ShowMessage('OpenOfficeWriter kann nicht gestartet werden!');
    Exit;
  end;
end;


es hakt noch etwas: Ungültige Klassenzeichenfolge ...
Welche "Kleinigkeit" muss da noch geändert werden?
Danke für Hilfe,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 21.05.10 10:10 
Ich mach das so
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function TOLE_OpenOffice.New(typ:String):boolean;
var rueckgabe : boolean;
begin
  try
    Document := Desktop.LoadComponentFromURL(
              'private:factory/'+typ,
              '_blank',
              0,
              VarArrayCreate([0, - 1], varVariant));
    rueckgabe := true;
  except
    rueckgabe := false;
  end;
  result := rueckgabe;
end;


Document ist ein Variant;
Typ ist in deinem Fall swriter

_________________
mfg. Joel
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 21.05.10 10:46 
Hi, Joel,
danke erst mal für deine Antwort!
Natürlich habe ich eine Frage, weil ich Fehlermeldungen bekomme:
1. Desktop ist bei mir nicht bekannt.

das wär's erst mal,
Gruß, Detlef

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Jo, alles klar, Desktop ist auch variant.

Ich danke dir!
Detlef

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Oh, leider zu früh gefreut ...
Brauch noch mal deine Hilfe.

_________________
ut vires desint, tamen est laudanda voluntas
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 21.05.10 12:14 
stimmt, da hab ich noch den connect vergessen. Sorry.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function TOLE_OpenOffice.Connect:boolean;
var rueckgabe : boolean;
begin
    try
      Service := CreateOleObject('com.sun.star.ServiceManager');
      Desktop := Service.createInstance('com.sun.star.frame.Desktop');
      rueckgabe := true;
    except
      rueckgabe := false;
    end;
    result := rueckgabe;
end;


Siehe Anhang, ich hab mir da ne klein Unit gebastelt.
Einloggen, um Attachments anzusehen!
_________________
mfg. Joel
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 21.05.10 15:07 
Hi, Joel,
jetzt bin ich platt!
Guck mal, schon 4 Downloads ...
Danke und viele Grüße,
Detlef

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Es gibt aber noch einen Fehler:
Inkompatible Typen TComponent Class und Class Reference

die Zeile stammt aus der .dpr

ausblenden Delphi-Quelltext
1:
Application.CreateForm(TOLE_OpenOffice, OLE_OpenOffice);					


Wie hat man denn damit umzugehen? Hatte ich noch nie, so eine Fehlermeldung ...

Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
SvenAbeln
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 334
Erhaltene Danke: 3



BeitragVerfasst: Sa 22.05.10 09:23 
Fällt dir hier etwas auf?
ausblenden Delphi-Quelltext
1:
2:
3:
Application.CreateForm(TOLE_OpenOffice, OLE_OpenOffice);

type TOLE_OpenOffice = class(TObject)

TOLE_OpenOffice ist gar kein Form, es macht also nicht viel Sinn es mit CreateForm zu erzeugen. :wink:


Zuletzt bearbeitet von SvenAbeln am So 23.05.10 10:14, insgesamt 1-mal bearbeitet
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 22.05.10 19:43 
Lieber Sven,

ich habe so meine Schwierigkeiten mit dem folgenden Textausschnitt:

"es macht also nicht viel sind es mit CreateForm zu erzeugen"

Kannst mal nachbessern? :)

Danke, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
SvenAbeln
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 334
Erhaltene Danke: 3



BeitragVerfasst: So 23.05.10 10:19 
user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:
Kannst mal nachbessern? :)
Ich hab den Tippfehler mal ganz unauffällig behoben :oops:

Falls sich noch jemand fragen sollte, wie man denn nun eine Instanz von TOLE_OpenOffice erzeugen kann:
ausblenden Delphi-Quelltext
1:
OLE_OpenOffice:= TOLE_OpenOffice.Create;					
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 23.05.10 10:52 
Hi, Sven,
nun ist es klar,
Danke, Detlef

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Hi, Delpher,
ich muss doch noch etwas weiter ausholen:

Ich will (bisher) nur prüfen, ob OpOff auf dem Rechner vorhanden ist, oder nicht und wollte es so
ähnlich wie bei MsWord machen, das ging nicht.
Dann hane ich mehrere andere Codes probiert, aber immer mit Fehlern.
Wenn ich den Code (siehe unten) nehme, gibt's noch: Variante referenziert kein Automatisierungsojekt.

Wer kann da mal schauen und es richtig stellen?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
function tBuchMain.Word_vorhanden: boolean;
begin
  Word_vorhanden := false;
  try
    MSWord := CreateOleObject('Word.Application');
    Word_vorhanden := true;
  except
    ShowMessage('Word kann nicht gestartet werden!');
    Word1.enabled := false;  // ist TMenuItem
    Exit;
  end;
end;
procedure TBuchMain.Word1Click(Sender: TObject);  // leere Seite
  begin if Word_vorhanden then begin MSWord.documents.add; MSWord.visible := true  end; end;

{function TBuchMain.ConnectOpOff:boolean;
var rueckgabe : boolean;
begin
    try
      Service := CreateOleObject('com.sun.star.ServiceManager');
      Desktop := Service.createInstance('com.sun.star.frame.Desktop');
      rueckgabe := true;
    except
      rueckgabe := false;
    end;
    result := rueckgabe;
end;}



function tBuchMain.OoffWriter_vorhanden(typ:String):boolean;
var rueckgabe : boolean;
begin
  try  //Document
    Ooffwri := Desktop.LoadComponentFromURL(
              'private:factory/'+typ,
              '_blank',
              0,
              VarArrayCreate([0, - 1], varVariant));
    rueckgabe := true;
  except
    rueckgabe := false;
  end;
  result := rueckgabe;
end;
procedure TBuchMain.OpenOfficeWriter1Click(Sender: TObject);
begin
  if OoffWriter_vorhanden('swriter') then
  begin
    showmessage('Staroffice ist vorhanden!');
    //OoffWri.documents.add; OoffWri.visible := true
  end;
end;


{procedure TBuchMain.CallStaroffice;
var
  sPfad,                    //Pfad der Vorlage, mit Dateinamen
  sDocument: String;        //Dokumentenpfad
  vDocument,                //
  vServiceManager,          //Ole-Objekt
  vStarDesktop,             //Instanz von vServiceManager
  ooValue,
  ooReflection,

  ooParams: Variant;

begin
  sPfad := GetCurrentDir + '\StarVor.stw';
  sDocument := 'file:///' + StringReplace(sPfad, '\', '/', [rfReplaceAll]);

  vServiceManager := CreateOleObject('com.sun.star.ServiceManager');
  vStarDesktop := vServiceManager.createInstance('com.sun.star.frame.Desktop');

  ooParams := VarArrayCreate([0, 0], varVariant);
  ooReflection := vServiceManager.createInstance('com.sun.star.reflection.CoreReflection');
  ooReflection.forName('com.sun.star.beans.PropertyValue').createObject(ooValue);
  ooValue.Name := 'AsTemplate';
  ooValue.Value := False;
  ooParams[0] := ooValue;

  vDocument := vStarDesktop.LoadComponentFromURL( sDocument, '_blank', 0, ooParams);

end; }


Danke

_________________
ut vires desint, tamen est laudanda voluntas
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: So 23.05.10 13:37 
user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:

Ich will (bisher) nur prüfen, ob OpOff auf dem Rechner vorhanden ist, oder nicht und wollte es so ähnlich wie bei MsWord machen, das ging nicht.
Wäre es nicht einfacher auf bestimmte Einträge der Registry zu prüfen, ob OpOff installiert ist? Vielleicht auch noch ob ein bestimmter Dateityp mit der gesuchten Application verknüpft ist...

LG Mario
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Mo 24.05.10 07:48 
Hi, Mario, et aliter

das könnte schon sein, ich weiß es nicht. Was mir bisher gepostet wurde, scheint ja auch schon (fast) richtig zu sein, aber leider fehlen mir auf dieser Ebene noch die Erfahrungen.

Ich sehe nicht, ob ich das Formular umbenennen muss, - statt form1 also OLE_OpenOffice, - oder

was der Unterschied ist zwischen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  vServiceManager := CreateOleObject('com.sun.star.ServiceManager');  oder
  Application.CreateForm(TOLE_OpenOffice, OLE_OpenOffice);            oder
  Document := Desktop.LoadComponentFromURL(
              'private:factory/'+typ,
              '_blank',
              0,
              VarArrayCreate([0, - 1], varVariant));                  oder
  OLE_OpenOffice:= TOLE_OpenOffice.Create;

Ja, das ist so meine Konfusion,
Detlef

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt

_________________
ut vires desint, tamen est laudanda voluntas