Announcement

Collapse
No announcement yet.

Mehrmaliges Öffnen von Word mit Delphi

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mehrmaliges Öffnen von Word mit Delphi

    Ich arbeite an einem Delphi-Programm von dem aus ich Microsoft Word starten möchte. Der Zugriff auf Word funktioniert schon ich habe allerdings das Problem, dass jedesmal das Word Programm neu gestartet wird und nicht einfach nur ein neues Fenster angelegt wird.
    Dies belastet unnötig den Arbeitsspeicher. Wie kann ich ein neues Fenster starten, ohne nochmals das gesammte Programm starten zu müssen.

  • #2
    Hallo Michael,

    das folgende Beispiel zeigt den Weg über die "späte Bindung".

    <pre><b>
    procedure TForm1.Button1Click(Sender: TObject);
    var
    word, word1: variant;
    begin
    word := createoleobject('word.application');
    word.documents.add;
    word.selection.TypeText(Text := 'das ist Seite 1');
    try
    word1 := getactiveoleobject('word.application');
    except
    on e: EOLESysError do
    word1 := createoleobject('word.application');
    end;
    word1.documents.add;
    word1.selection.TypeText(Text := 'das ist Seite 2');
    word.wordbasic.appshow; <font color="#008080">{dient nur zum sichtbarmachen von
    Winword}</font>
    end;
    </pre></b>

    Tschüß

    Torsten

    PS: Du wolltest mir noch eine E-mail schicken

    Comment


    • #3
      Eine allgemeinere Lösung bietet FindWindow in Verbindung mit ShowWindow:

      var hForm: hWnd; // begin // hForm := FindWindow( 'OpusApps', nil ); // dies geht leider nur dann, wenn die WindowClass des gewünschten Programms bekannt ist; für Word ist 'OpusApps' aus der Literatur bekannt, für eigene Applikationen ist es die Klasse des Hauptformulars // if hForm = 0 // Programm noch nicht gestartet // then begin ... end else begin // ShowWindow( hForm, SW_RESTORE ); // SetForegroundWindow( hForm ); // end; // end;

      Viel Erfolg! Jürge

      Comment

      Working...
      X