如何将此代码从vb6转换为delphi

时间:2017-08-21 06:33:00

标签: vba delphi-7

Private Sub acak ( )
Dim random As New Random ( )
Dim a, c, m, i, y As Byte
Dim x( ) As Byte = {0,1,2,3,4,5,6,7,8,9,10}
a = 5
c = 7
m = 8
x (0) = random.Next (1, 16)
For i = 1 To 16
       x(i) = (a*x(i-1)+c) Mod m
       If x(i) = 0 Then
           y = i
       End if
 Next
 Button1.Text = x(16)
 acakbutton ()

结束子

请帮助我,因为我无法使用vb而且我无法转换它,因为我还是新手

1 个答案:

答案 0 :(得分:1)

它看起来像这样:

interface

uses
 ...;

type
  TMyForm = class(TForm)
    Button1: TButton;
    ... 
  private
    procedure acak;
   ... 
  end;

...

implementation

uses
  Math;

procedure TMyForm.acak;
var
  a, c, m, i, y: Byte;
  x: array[0..16] of Byte;
begin
  Randomize;
  for i := 0 to 10 do
    x[i] := i;
  a := 5;
  c := 7;
  m := 8;
  x[0] := RandomRange(1, 16);
  for i := 1 to 16 do
  begin
    x[i] := (a*x[i-1]+c) mod m;
    if x[i] = 0 then
      y := i;
  end;
  Button1.Text := IntToStr(x[16]);
  acakbutton;
end;