VB6 : working with Word documents 30 September 2002 at 00:00
The following shows how to programmatically open, modify, save and close a word document.
var
  oWordApp: Variant;
  oBookmark: Variant;
  oRange: Variant;
begin
  try
    oWordApp := CreateOleObject('Word.Application');
  except on E: Exception do
    begin
    ShowMessage('Word does not appear to be installed: ' + E.Message);
    Exit;
    end;
  end;
  // open the document and manipulate text
  try
    begin
    oWordApp.Visible := False;
    oWordApp.Documents.Open(FileName);
    oBookmark := WordApp.ActiveDocument.Bookmarks.Item('NamedBookark');
    oRange := oBookMark.Range;
    oRange.Select;
    oRange.Text := 'New text that you have written!';
    oRange := Unassigned;
    oBookmark := Unassigned;
    oWordApp.ActiveDocument.Save;
    end;
  except on E: Exception do
    begin
    ShowMessage('Unable to generate report: ' + E.Message);
    end;
  end;
  // close word and clean up
  oWordApp.Quit;
  oWordApp := Unassigned;
end;
Loading images from Jar Files 12 September 2002 at 00:00
  try {
    URL url = FreeArchiver.class.getResource("/images/yourimg.gif"); 
    // the following line is necessary to be able to catch the exception if
    // the image does not exist in the resource
    url.getFile();
    Image img = Toolkit.getDefaultToolkit().getImage(url); 
    setIconImage(img);
  }
  catch (Exception e) {
    System.err.println("Unable to load image from archive.");
  }
Creating ActiveX controls for the web 26 September 2002 at 00:00
To create ActiveX controls for your web page, do the following:
  1. Start a new ActiveX control project
  2. Build your OCX and register it by clicking Run..Register ActiveX Server
  3. Using regedit, search for you project name and get the GUID of your ActiveX control
  4. Create your HTML page with the object code, for example
    <OBJECT 
        CLASSID="clsid:B5338580-D097-11D6-B92D-00B0D08ACA9F" 
        CODEBASE="http://localhost/controls/MyControl.ocx#ver=2,0,0,0" 
        WIDTH="640" 
        HEIGHT="480">
    <PARAM NAME="angle" VALUE="90">
    </OBJECT>
    
    where clsid is the GUID you just retrieved and #ver= determines when the client requests the latest version of the OCX - if the version on their machine does not match 2,0,0,0 as in this example, it will be downloaded from the server, otherwise the version on their machine will be used.
  5. Click Run..Parameters
  6. Set the Host Application to your browser exe e.g. C:\Program Files\Internet Explorer\IEXPLORE.EXE
  7. Set the Parameters field to your web page e.g. http://localhost/mypage.htm
  8. Unregister the ActiveX control by clicking Run..Unregister ActiveX Server
  9. The setup is now complete. You can run the project as normal - although it will now appear in the browser that is loaded.
  10. Whenever you have finished testing, you will need to close the new browser window, and unregister the activex control
Working with word documents in Delphi 30 September 2002 at 00:00
The following shows how to programmatically open, modify, save and close a word document.
var
  oWordApp: Variant;
  oBookmark: Variant;
  oRange: Variant;
begin
  try
    oWordApp := CreateOleObject('Word.Application');
  except on E: Exception do
    begin
    ShowMessage('Word does not appear to be installed: ' + E.Message);
    Exit;
    end;
  end;
  // open the document and manipulate text
  try
    begin
    oWordApp.Visible := False;
    oWordApp.Documents.Open(FileName);
    oBookmark := WordApp.ActiveDocument.Bookmarks.Item('NamedBookark');
    oRange := oBookMark.Range;
    oRange.Select;
    oRange.Text := 'New text that you have written!';
    oRange := Unassigned;
    oBookmark := Unassigned;
    oWordApp.ActiveDocument.Save;
    end;
  except on E: Exception do
    begin
    ShowMessage('Unable to generate report: ' + E.Message);
    end;
  end;
  // close word and clean up
  oWordApp.Quit;
  oWordApp := Unassigned;
end;