Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:07:41+00:00 2026-05-31T16:07:41+00:00

I’m trying to execute this code (this is a minimal sample in order to

  • 0

I’m trying to execute this code (this is a minimal sample in order to use CreateOleObject) from inside of a dwscript

function GetFileVersion(const FileName: string): string;
var
  V : OleVariant;
begin
  V  := CreateOleObject('Scripting.FileSystemObject');
  Result := V.GetFileVersion(FileName);
end;

So far i tried this

{$APPTYPE CONSOLE}

{$R *.res}


uses
  SysUtils,
  ComObj,
  ActiveX,
  dwsComp,
  dwsCompiler,
  dwsExprs,
  dwsCoreExprs;


procedure Execute;
var
  LScript: TDelphiWebScript;
  LUnit: TdwsUnit;
  LProg: IdwsProgram;
  LExec: IdwsProgramExecution;
begin
  LScript := TDelphiWebScript.Create(NIL);
  LUnit := TdwsUnit.Create(NIL);
  try
    LUnit.UnitName := 'Foo';
    LUnit.Script := LScript;
    //  compile a simple script
    LProg := LScript.Compile(
      'function GetFileVersion(const FileName: string): string;'+sLineBreak+
      'var'+sLineBreak+
      '   V : Variant;'+sLineBreak+
      'begin'+sLineBreak+
      ' V  := CreateOleObject(''Scripting.FileSystemObject'');'+sLineBreak+
      ' Result := V.GetFileVersion(FileName);'+sLineBreak+
      'end;'+sLineBreak+
      ''+sLineBreak+
      'PrintLn(GetFileVersion(''Foo''));'+sLineBreak+
      ''
    );

    if LProg.Msgs.HasErrors then begin
      Writeln(LProg.Msgs.AsInfo);
      Exit;
    end;

    try
      LExec := LProg.Execute;
    except
      on E: Exception do
        WriteLn(E.Message + sLineBreak + LExec.Msgs.AsInfo );
    end;
    Writeln(LExec.Result.ToString);
  finally
    LScript.Free;
  end;
end;

begin
  try
    Execute;
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

But i’m getting this error message

Syntax Error: Unknown name “CreateOleObject” [line: 5, column: 8]

the question is how i can execute the CreateOleObject function using dwscript?

UPDATE

Following the Linas suggestions I could finally resolve the issue.

This is a sample working application

uses
  SysUtils,
  ComObj,
  ActiveX,
  dwsComp,
  dwsCompiler,
  dwsExprs,
  dwsComConnector,
  dwsCoreExprs;


procedure Execute;
var
  LScript: TDelphiWebScript;
  LUnit: TdwsUnit;
  LProg: IdwsProgram;
  LExec: IdwsProgramExecution;
  LdwsComConnector : TdwsComConnector;
begin
  LScript := TDelphiWebScript.Create(NIL);
  LdwsComConnector:=TdwsComConnector.Create(nil);
  LdwsComConnector.Script:=LScript;
  LUnit := TdwsUnit.Create(NIL);
  try
    LUnit.UnitName := 'Foo';
    LUnit.Script := LScript;
    //  compile a simple script
    LProg := LScript.Compile(
      'function GetFileVersion(const FileName: string): string;'+sLineBreak+
      'var'+sLineBreak+
      '   V : OleVariant;'+sLineBreak+
      'begin'+sLineBreak+
      ' V  := CreateOleObject(''Scripting.FileSystemObject'');'+sLineBreak+
      ' Result := VarToStr(V.GetFileVersion(FileName));'+sLineBreak+
      'end;'+sLineBreak+
      ''+sLineBreak+
      'PrintLn(GetFileVersion(''C:\Bar\Foo.exe''));'+sLineBreak+
      ''
    );

    if LProg.Msgs.HasErrors then begin
      Writeln(LProg.Msgs.AsInfo);
      Exit;
    end;

    try
      LExec := LProg.Execute;
    except
      on E: Exception do
        WriteLn(E.Message + sLineBreak + LExec.Msgs.AsInfo );
    end;
    Writeln(LExec.Result.ToString);
  finally
    LScript.Free;
    LdwsComConnector.Free;
  end;
end;

begin
 try
    CoInitialize(nil);
    try
      Execute;
      Readln;
    finally
      CoUninitialize;
    end;
 except
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:07:42+00:00Added an answer on May 31, 2026 at 4:07 pm

    This can be accomplished in two ways.

    1 way: You must drop TdwsComConnector (from unit dwsComConnector) to your data module or form (or create it manually) and assign your script instance to it. e.g.:

    dwsComConnector1.Script := LScript;
    

    2 way:

    interface
    
    uses
      dwsFunctions, dwsSymbols, dwsExprs;
    
    type
      TCreateOleObjectFunc = class(TInternalFunction)
        procedure Execute(info : TProgramInfo); override;
      end;
    
    implementation
    
    uses 
      OleAuto;
    
    { TCreateOleObjectFunc }
    
    procedure TCreateOleObjectFunc.Execute(info : TProgramInfo);
    begin
      Info.ResultAsVariant := CreateOleObject(Info.ValueAsString['ClassName']);
    end;
    
    initialization
      RegisterInternalFunction(TCreateOleObjectFunc, 'CreateOleObject', ['ClassName', cString], cVariant, True);
    

    This will expose CreateOleObject function to DWScript so you could use it.

    Also you should declare your V as OleVariant instead of Variant and change the line to Result := VarToStr(V.GetFileVersion(FileName)); to make it work properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.