Pascal

Pascal is an influential imperative and procedural programming language, largely (but not exclusively) intended to teach students structured programming and data structuring. Pasca was implemented on a wide range of architectures, from early PCs to mainframes. Pascal derivatives include OOP-based Object Pascal (used in Delphi and Lazarus/Free Pascal). Pascal is a purely procedural language and includes control statements with reserved words, but has many data structuring facilities and other abstractions like type definitions, records, pointers, enumerations, and sets.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello programming experts! I am having a memory problem that cannot explain root cause, please help me! The problem is as follows: My program throws exception when i exit. I investigated and thought that the cause of the error was the use Copymemory function to copy the record containing the variable have string data type.

Below is my demo program by delphi 2009: In my project,  I added 2 file project dpr then add sharedmemory for use BorlndMM.dll instead of using FastMM memory management. I define a struct containing a String variable. Allocate 1 array of 2048 PByte elements. Use Memory Copy function to copy 2 struct. finally, Free array 2048. when i exit program, my program threw exception.
type   
 TMyStructure = record
 F1: TMyStructure;

Open in new window

unit 1
procedure TForm9.FormCreate(Sender: TObject);
var
    i: Integer;
begin
    F1.str1 := 'This is a string to demo for copying the String data type 
                                            using the Copymemory method';
end;

Open in new window

unit 2
procedure TForm8.btn1Click(Sender: TObject);

var
Form9: TForm9;
i: Integer;
s1: array[0..2048-1] of PByte;
begin
    //  Alloc 1st 2048 segments, each segment gain 1KB
    for i := 0 to Length(s1) - 1 do
    begin

    s1[i] := AllocMem(1024);
end;

//  Create Form9
Form9 := TForm9.Create(Owner);

//  -> ERROR
CopyMemory(@Self.F1, @Form9.F1, SizeOf(TMyStructure));

//  -> OK
//  Self.F1 := Form9.F1;

// Free memory s1 array
for i := 0 to Length(s1) - 1 do
begin
    FreeMem(s1[i]);
end;
end;

Open in new window

0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Hi, I've been banging my head with trying to come up with a way on Pascal on how to create a function that saves an array of byte to file while keeping its integrity from the fist to the last byte.

I came up with two ideas, either I save the data to the file in its binary form or I convert the binary to hex then save.
When I need to load, if its hex I can decode and convert it to an array of bytes again.

I'm really stuck, because I looked over alot on the past days and didnt find anything remotely close to it. I've began recently working with Pascal so I'm not that experienced with it.
Going C++ would solve me issue but that is not an option here, I need to do it on Pascal.

So if anyone could come up with a way for me to save the array of bytes then load it again later on I would be really thankful.

I could also use a function to encode/decode the bytes, but i have no clue on how would that work.

This is the array I need to save

hmm: array [0..18954] of BYTE;

I have pretty much no base code cause everything I came up with brings error on the IDE, sorry.
0
I have big problem with StringList. I have text file with text like this:

     
51,179 km=Powiat Ostrzeszowski
    51,179 - 61,402 km=Powiat Wieruszowski
    61,402 - 64,559 km (d. DW450)=Powiat Wieruszowski
    64,559 km (d. DW450)=Powiat Kępiński 

Open in new window


I want to import this file and show first values, before "=" in RadioGroup. Second values after "=" i want to show on Label in moment when user clicks proper value on RadioGroup.

I would like to operate on Names and Values of StrongList.

Something like this: https://i.stack.imgur.com/dkLih.png

In *.pas file I have:

     
var
      Form1: TForm1;
      list: TStringList;
      i: Integer; 

Open in new window


On FormCreate:

   
 list := TStringList.Create;    
    list.LoadFromFile('dat\a1pik.dat');
    RadioGroup1.Visible := true;
    RadioGroup1.Items.Clear;

    for i := 0 to list.Count-1 do
        begin
            RadioGroup1.Items.Add(list.Names[i]);
        end;

And first values I have on RadioGroup. 

Open in new window


I try with RadioGroup like this:

     
procedure TForm1.RadioGroup1Click(Sender: TObject);
        begin
        Label.Caption := list.Values[list.Names[RadioGroup1.ItemIndex]];
        end; 

Open in new window


But doesn't work. What I do wrong?

P.S. Sorry for my English :)
0
Hi, when i use a quick twebbrowser command.
and i use the following link to test a code, it doesnt show.
How can i rectrifie this?

So i put a path in my delphi app to open the link inside the twebbrowser..
after it logs in my acc, and advances to the path, it just shows a black screen.

https://account.xbox.com/en-GB/PaymentAndBilling/RedeemCode?doRedeem=0&token=xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
0
Hi,

I have to create a program to communicate with 50 machines.

I'm using ClientSocket, because the machines will be the server connection.

I tried to create dynamically and manually (one-by-one), but after several hours, the error 10055 is appearing.

I tried too create only one connection with unknown IP and the message is happening again.

  if not(ClientSocket1.Active) then
  begin
    ClientSocket1.Socket.Close;
    ClientSocket1.Close;
    ClientSocket1.Active := True;
  end;

I put this inside a button.

About all errors, I created a routine:
procedure TForm1.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
 if ErrorCode>0  then
  begin
    ClientSocket1.Socket.Close;
    ClientSocket1.Close;
    if Socket = ClientSocket1.Socket then ClientSocket1.Active := True;
  end;
end;

This way I was thinking that I could fixed every timeout, but nothing yet.

Please, can someone help me?

Best Regards
Wellington
0

Pascal

Pascal is an influential imperative and procedural programming language, largely (but not exclusively) intended to teach students structured programming and data structuring. Pasca was implemented on a wide range of architectures, from early PCs to mainframes. Pascal derivatives include OOP-based Object Pascal (used in Delphi and Lazarus/Free Pascal). Pascal is a purely procedural language and includes control statements with reserved words, but has many data structuring facilities and other abstractions like type definitions, records, pointers, enumerations, and sets.

Top Experts In
Pascal
<
Monthly
>