Visual Basic -> Delphi

Can anyone help me to transform this Visual Basic code into Delphi:

Option Explicit

Private mSystem(1 To 13) As String
Private mFileNumber As Integer

Private Sub Command1_Click()
    mSystem(1) = "1"
    mSystem(2) = "x"
    mSystem(3) = "2"
    mSystem(4) = "x2"
    mSystem(5) = "1x"
    mSystem(6) = "1"
    mSystem(7) = "2"
    mSystem(8) = "2"
    mSystem(9) = "x"
    mSystem(10) = "1x"
    mSystem(11) = "2"
    mSystem(12) = "2"
    mSystem(13) = "1"
   
    mFileNumber = FreeFile
    Open "c:\system.txt" For Output As mFileNumber
    PrintSystem "", 1
    Close mFileNumber
    Shell "notepad.exe c:\system.txt", vbNormalFocus
End Sub

Private Sub PrintSystem(ByVal row As String, ByVal level As Integer)
    If level = 14 Then
        Print #mFileNumber, row
    Else
        Dim i As Integer
        For i = 1 To Len(mSystem(level))
            PrintSystem row & Mid(mSystem(level), i, 1), level + 1
        Next i
    End If
End Sub
strobe0Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AmigoJackCommented:
uses ShellApi;

var
  mSystem: array[1..13] of String;
  mFileNumber: text;

procedure PrintSystem(row: String; level: Integer);
var
  i: integer;
begin
    If level = 14 Then Write(mFileNumber, row) else begin
        For i := 1 To Length(mSystem[level]) do PrintSystem(row+ copy(mSystem[level], i, 1), level + 1);
    End;
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
    mSystem[1] := '1';
    mSystem[2] := 'x';
    mSystem[3] := '2';
    mSystem[4] := 'x2';
    mSystem[5] := '1x';
    mSystem[6] := '1';
    mSystem[7] := '2';
    mSystem[8] := '2';
    mSystem[9] := 'x';
    mSystem[10] := '1x';
    mSystem[11] := '2';
    mSystem[12] := '2';
    mSystem[13] := '1';
   
    AssignFile(mFileNumber, 'c:\system.txt');
    Rewrite(mFileNumber);
    PrintSystem('', 1);
    CloseFile(mFileNumber);

    ShellExecute(0, nil, 'notepad.exe', 'c:\system.txt', nil, SW_SHOWNORMAL);
End;


----------------------

that would be quite a 1:1 translation :) however, to make it more easy for you, simply start delphi, create a new application, add a TButton and then replace ALL OF THE prewritten code with the one below:

-----------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ShellApi,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  mSystem: array[1..13] of String;
  mFileNumber: text;

implementation

{$R *.DFM}


procedure PrintSystem(row: String; level: Integer);
var
  i: integer;
begin
    If level = 14 Then Write(mFileNumber, row) else begin
        For i := 1 To Length(mSystem[level]) do PrintSystem(row+ copy(mSystem[level], i, 1), level + 1);
    End;
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
    mSystem[1] := '1';
    mSystem[2] := 'x';
    mSystem[3] := '2';
    mSystem[4] := 'x2';
    mSystem[5] := '1x';
    mSystem[6] := '1';
    mSystem[7] := '2';
    mSystem[8] := '2';
    mSystem[9] := 'x';
    mSystem[10] := '1x';
    mSystem[11] := '2';
    mSystem[12] := '2';
    mSystem[13] := '1';

    AssignFile(mFileNumber, 'c:\system.txt');
    Rewrite(mFileNumber);
    PrintSystem('', 1);
    CloseFile(mFileNumber);

    ShellExecute(0, nil, 'notepad.exe', 'c:\system.txt', nil, SW_SHOWNORMAL);

end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
strobe0Author Commented:
Thanks a lot for your answer, AmigoJack!

Is there a way to save the output to memory instead of a file?
0
AmigoJackCommented:
of course, but how do you mean that? for example: everything youre writing to the file could also be held by a single string.
0
strobe0Author Commented:
Can you give an example how I should code this if I want to save it in a string?
0
AmigoJackCommented:
thats pretty simple :) i recommend you to check what i have changed compared to my other content of "unit1.pas" - i think this will help you most to append other changes in the same way and help to understand it:

(instead of writing it to a file, everything is put together into one string, which then will be displayed. for this you have to add a TMemo to the new project as well)

------------------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ShellApi,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  // this is a comment: variables declared here are accessable anywhere
  // so you can also define here the all-in-one string
var
  Form1: TForm1;
  mSystem: array[1..13] of String;
  sFullText: string;

implementation

{$R *.DFM}


procedure PrintSystem(row: String; level: Integer);
var
  i: integer;
begin
    If level = 14 Then sFullText:= sFullText+ row else begin
        For i := 1 To Length(mSystem[level]) do PrintSystem(row+ copy(mSystem[level], i, 1), level + 1);
    End;
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
    mSystem[1] := '1';
    mSystem[2] := 'x';
    mSystem[3] := '2';
    mSystem[4] := 'x2';
    mSystem[5] := '1x';
    mSystem[6] := '1';
    mSystem[7] := '2';
    mSystem[8] := '2';
    mSystem[9] := 'x';
    mSystem[10] := '1x';
    mSystem[11] := '2';
    mSystem[12] := '2';
    mSystem[13] := '1';

    sFullText:= '';  // initialize it = means we set it to empty
    PrintSystem('', 1);

    // here goes our final string
    Memo1.text:= sFullText;

end;

end.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.