pascal

Catching stack-trace in Free Pascal

I have a console application written in Free Pascal, that like most larger applications sometimes crashes. As this application is live, I usually ask people to write me down the stack-trace on crash -- I distribute it with both debug and lineinfo. However, the application uses FPC video.pas output, and sometimes the text output stacktrac...

One complex task.

Here is a task: "3 brothers have to transfer 9 boxes from one place to another. These boxes weigh 1, 2, 4, 5, 6, 8, 9, 11, 14 kilos. Every brother takes 3 boxes. So, how to make a program that would count the most optimal way to take boxes? The difference between one brother's carrying boxes weight and other'...

Pascal compiler running on the server

Hi all, do you have any ideas, how to compile pascal file (*.pas) on the server? Thank you. ...

Why does Pascal forbid modification of the counter inside the for block?

Is it because Pascal was designed to be so, or are there any tradeoffs? Or what are the pros and cons to forbid or not forbid modification of the counter inside a for-block? IMHO, there is little use to modify the counter inside a for-block. EDIT: Could you provide one example where we need to modify the counter inside the for-block? ...

Why do pascal forbid same identifier name for method's parameter and class's data member?

type TPerson = class(TObject) name : string; constructor create(name : string); end; would trigger compiler error. I think a self or this pointer/reference is good enough,for its clarity.So,what are the advantages of doing so? EDIT: One more question,could you show what are the other languages that depoly this...

What is the best way to join 2 records in Pascal?

Hi, I've a little problem with records in Pascal. I'm writting a program where I've got two lists of records: one with patients and second with diseases but I don't have idea how to join it. I was trying to do a dynamic table with diseases id's in patient list but lazarus had problems with compiling it. I would be glad if someone helps m...

All array possibilities

I have pascal code (programming language actually doesn't mean anything): box[1] := 14; box[2] := 2; box[3] := 4; box[4] := 5; box[5] := 6; box[6] := 8; I want to get all possibilities. For instance, box[1] = box[6], then box[6] = box[1]. Yes, I can write it by my hand, but I guess I can make it more clever, by loop. Any ...

Object crashing when in main program, but not when moved to unit

I've written a custom SDL GUI toolkit (source is on http://sourceforge.net/projects/lkgui/files/) and I'm having an issue with an inherited object. When the object is within the main program, the constructor isn't called hence the program doesn't properly initialise the object and it crashes after some commands (Specifically, TStartGame...

Call function by memory address in Pascal - Delphi

Hi all. I have a function in C++ that I call with its memory address with typedef, and I want to do the same thing in Delphi. typedef void (*function_t)(char *format, ...); function_t Function; Function = (function_t)0x00477123; And then, I call it with: Function("string", etc); I tried to do this in Delphi, but got no results. I...

Reading integer numbers in Pascal

Hi guys, I'm using Pascal. I have a problem when dealing with reading file. I have a file with integer numbers. My pascal to read the file is: read(input, arr[i]); if my file content is "1 2 3" then it's good but if it is "1 2 3 " or "1 2 3(enter here)" (there is a space or empty line at the end) then my arr will be 1 2 3 0. How ...

Summing Numerical Character String

Hey everyone, I'm having an issue with my programming assignment where I cycle through a string and sum the integer value of character. As the following code states. Now I pass a string into this subroutine. For example given num := '8888'; Expected Output would be 32 Resulting output is -12 I'm using fpc pascal compiler on a Li...

InnoSetup & Pascal - Type mismatch error on run even after successful compile

When I compile the code below, it completes without errors, but when I attempt to run the setup file I get a type mismatch error. Can anyone tell me what might be causing it? (exact error message is "Runtime Error (at 1:66): Type Mismatch.") [Setup] DefaultDirName={code:AppDir}\MyApp [Code] function AppDir(Param: String): String; var ...

Getting the number of rows and columns actually populated with data of a N x M Array

I am writing some matrix routines in Delphi and this problem came up. I have defined a real matrix thus:- RealArrayNPbyNP = Array[1..200,1..200] of Extended; I have populated this array with a 5 x 6 matrix. How do I query the array to get the number of rows (which in this case will be 5) and the number of cols (which in this case will...

Sort a string list: Move or exchange items only

In Delphi / Pascal I would like to sort a TStringList alphabetically. But for this purpose, I can only use the following two methods: Move: Moves a string from one index position to another, shifting other strings around as appropriate. Exchange: Swaps two strings in the list, as identified by their index positions. How could I do thi...

Playlist for music player in Delphi / List of multiple data items

I would like to have a playlist for my own music player in Delphi / Pascal. I thought that it would be the best solution to have a TStringList with the path of the MP3 file and - additionally - a TListBox with the song names. The matching strings in both lists must be at the same position. So if the user chooses item 5 in TListBox I can...

Does C++ have "with" keyword like Pascal?

with keyword in Pascal can be use to quick access the field of a record. Anybody knows if C++ has anything similar to that? Ex: I have a pointer with many fields and i don't want to type like this: if (pointer->field1) && (pointer->field2) && ... (pointer->fieldn) what I really want is something like this in C++: with (pointer) { ...

Creating a Binary Tree for a Knockout Tournament

I am trying to create a binary tree for use in a knockout tournament. The tree consists of TNodes with Left and Right pointers. This is the code that I have come up with (below); however, it runs into difficulties with the pointers in the CreateTree section. Once this creates an empty tree of large enough size, I need to add the names ...

How does the Delphi / Borland Pascal STR procedure round

Both, Borland Pascal 7 and Delphi 2007 have got the procedure STR which takes a number, a length and precision and converts it to a string like this: str(9.234:5:1, s); // -> s = ' 9.2' All is fine if the rounding is non-ambiguous, but if it isn't (0.5 -> up or down?) there is a problem: It seems to depend on the floating point data ...

Pascal programming help

I posted this earlier and it got closed because I did not show my try at coding it, so here is the question: SECTIONS $160 = section 1 $220 = section 2 $280 = section 3 $350 = section 4 $425 = section 5 Develop pseudocode that accepts as input the name of an unspecified number of masqueraders who each have paid the full cost of their ...

Help With Applying Pseudocode To Pascal

Begin Fail = 0 Pass = 0 Read Mark While Mark is > < = Do If Mark > 50 then Pass = Pass + 1 Else Fail = Fail + 1 EndIf Read Mark EndDo Total = Pass + Fail Print "No. Of Students Who Pass",PASS Print "No. Of Students Who Fail",FAIL Print "No. Of Students Taken The Exam",TOTAL End ...