Jumat, 30 April 2021

mengganti variabel global S bertipe string menggunakan fungsi

program Project5string;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils;

procedure Foo(var S: Openstring);
begin
  Writeln('S length :',Length(S)); { 5 }
  Writeln('S high ', High(S)); { 10 }
  Writeln('S MEMAKAN MEMORY KOMPUTER SEBESAR ', SizeOf(S)); {  11 bYTES }
  Writeln('S length :',Integer(S[0])); { 5 }
  //Writeln(S[1]); { C }
  S[1] := 'T';    // isi variabel S poisi ke satu diganti T
end;

var
  S: String[10];    // DEFINI VARIABEL s BERTIPE sTRING

begin try
  S := 'Corfu';
  Writeln('sebelum memanggil fungsi Foo berisi ',S[1]);
  Foo(S);    // memanggil fungsi Foo untuk mengubah isi S
  Writeln(' setelahnya berisi ',S[1]); { akan menampilkan huruf T bukan C lagi }
  Readln;

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

konversi nilai variabel byte dan integer pada delphi 10

copas kode dibawah ini :
uses
  System.SysUtils;

var
  // Declare two of the basic intrinsic types that have helpers.
  // The others are: ShortInt, SmallInt, Word, Cardinal, NativeInt, NativeUInt and Int64.
  // The methods used in this code example apply to all the types mentioned above.
  myByte: Byte;
  myInteger: Integer;

const
  myString: String = '12345678910111211314';

begin
  try
  myByte := myByte.MaxValue; //255
  myInteger := myInteger.MaxValue;  //2147483647

  writeln('Byte value: ', myByte);
  writeln('Byte value as hexadecimal string using four digits: ',
    myByte.ToHexString(Integer(4)));
  writeln('Byte value as string: ', myByte.ToString());

  // Tries to convert myString to an Integer.
  if myInteger.TryParse(myString, myInteger) then
  begin
    writeln('The new value of myInteger is:', myInteger);
  end
  else
  begin
  //In case the conversion does not succeed,
  //the next statement will try to convert the myByte number
  //to a string.
  //The string returned will be converted to an integer value
  //with the Parse function.
    myInteger := myInteger.Parse(myByte.ToString());
    writeln('The new value of myInteger is:', myInteger);
  end;

  readln;


  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
hasil output program bila dijalankan seperti ini :

Cara menggunakan box2D pada delphi console

uses
  System.SysUtils, Box2D.Collision, Box2D.Common,
  Box2D.Dynamics,
  Box2D.Rope, Box2DTypes;

var
  gravity: b2Vec2;
  world: b2WorldWrapper;
  groundBodyDef: b2BodyDef;
  groundBody: b2BodyWrapper;
  groundBox: b2PolygonShapeWrapper;
  bodyDef: b2BodyDef;
  body: b2BodyWrapper;
  dynamicBox: b2PolygonShapeWrapper;
  fixtureDef: b2FixtureDef;
  timeStep, angle: Single;
  velocityIterations, positionIterations, i: Integer;
  position: b2Vec2;
begin
  try
    // Define the gravity vector.
    gravity := b2Vec2.Create(0.0, -10.0);

    // Construct a world object, which will hold and simulate the rigid bodies.
    world := b2WorldWrapper.Create(gravity);

    // Define the ground body.
    groundBodyDef := b2BodyDef.Create;
    groundBodyDef.position.&Set(0.0, -10.0);

    // Call the body factory which allocates memory for the ground body
    // from a pool and creates the ground box shape (also from a pool).
    // The body is also added to the world.
    groundBody := world.CreateBody(@groundBodyDef);

    // Define the ground box shape.
    groundBox := b2PolygonShapeWrapper.Create;

    // The extents are the half-widths of the box.
    groundBox.SetAsBox(50.0, 10.0);

    // Add the ground fixture to the ground body.
    groundBody.CreateFixture(groundBox, 0.0);

    // Define the dynamic body. We set its position and call the body factory.
    bodyDef := b2BodyDef.Create;
    bodyDef.&type := b2_dynamicBody;
    bodyDef.position.&Set(0.0, 4.0);
    body := world.CreateBody(@bodyDef);

    // Define another box shape for our dynamic body.
    dynamicBox := b2PolygonShapeWrapper.Create;
    dynamicBox.SetAsBox(1.0, 1.0);

    // Define the dynamic body fixture.
    fixtureDef := b2FixtureDef.Create;
    fixtureDef.shape := dynamicBox;

    // Set the box density to be non-zero, so it will be dynamic.
    fixtureDef.density := 1.0;

    // Override the default friction.
    fixtureDef.friction := 0.3;

    // Add the shape to the body.
    body.CreateFixture(@fixtureDef);

    // Prepare for simulation. Typically we use a time step of 1/60 of a
    // second (60Hz) and 10 iterations. This provides a high quality simulation
    // in most game scenarios.
    timeStep := 1.0 / 60.0;
    velocityIterations := 6;
    positionIterations := 2;

    // This is our little game loop.
    for I := 0 to 59 do
    begin
      // Instruct the world to perform a single step of simulation.
      // It is generally best to keep the time step and iterations fixed.
      world.Step(timeStep, velocityIterations, positionIterations);

      // Now print the position and angle of the body.
      position := body.GetPosition^;
      angle := body.GetAngle;

      WriteLn(Format('%4.2f %4.2f %4.2f', [position.x, position.y, angle]));
    end;

    // When the world destructor is called, all bodies and joints are freed.
    // This can create orphaned pointers, so be careful about your world
    // management.
    world.Destroy;

    ReadLn;
    
    

Belajar mengisi tipe Trect fungsi bound pada Delphi Console

tambahkan code pada proect anda seperti ini
uses
  System.SysUtils,
  System.Types;

var
  aRectangle:TRect;

begin
  try
    aRectangle := Bounds(4,5,16,25);
    {
    equivalent to:
      aRectangle.Left := 4;
      aRectangle.Top := 5;
      aRectangle.Width := 16;
      aRectangle.Height := 25;
    }

    WriteLn('batas kiri ',aRectangle.Left,' batas atas ', aRectangle.Top,
     ' batas kanan ',aRectangle.Right,' batas bawah ',aRectangle.Bottom);

    readln; 

Menampilkan Hello World di Delphi 10 console

Buka Delphi buat project baru tipe aplikasi console tampilan akan seperti ini :

kemudian ketik dua baris code dibawah perintah try seperti ini :
    writeln('Hello world');
    readln;
    

Kemudian Jalankan maka tampilan klo berhasil harus seperti ini

Belajar bahasa pascal Mode Console di Delphi 10

Tahun 2017 ini saya menginstal delphi vwersi 10, lumayanlah untuk berjalan di laptop Core_i3 ku.

Kamis, 30 Juni 2016

whats up in 2016

long time ago since 2013 not post any. learn some code.. lazy dizzy era. 2014 still busy with workhour... but i took course of programming using pascal. 2015 i move from central office to branch office. i never create code again. poor me. 2016 well in this year.. statring nu life.. still doing some cool code.. micro controller with C. omg.. i dont' using pascal anymore ??? sorry to read that..