pascal

Pascal Syntax Error

家住魔仙堡 提交于 2019-12-13 12:51:08
问题 I have the following function in my program: function Getrand(rStart,rEnd:Integer): Integer; var diff: Integer; begin diff := rEnd - rStart; Getrand := Random(diff) + rStart; end; When I try to compile the program, I get this error: Failed when compiling Line 27: [Error] (27:9): Invalid number of parameters in script What am I doing wrong? 回答1: Perhaps your flavour of Pascal doesn't support the traditional return value syntax. Try Result := … instead of Getrand := … . 回答2: you can use Exit

I'm getting an Error:Illegal Expression

女生的网名这么多〃 提交于 2019-12-13 11:22:50
问题 I get this error: illegal expression and Fatal: Syntax error, ; expected but : found The Pascal code is below: Program PaidUp; const size=30; var payment,totm1,totm2,totm3:real; section1,section2,section3,i,j,idnum:integer; IDNUMARR:array[1..999] of integer; PAYMENTARR:array[1..size] of real; Procedure InitialiseVariables; {This procedure initialises all variables used in the program} Begin idnum:=0; payment:=0; totm1:=0; totm2:=0; totm3:=0; section1:=0; section2:=0; section3:=0; i:=0; j:=0;

CreateProcess using netsh hangs/freezes the application [Delphi]

∥☆過路亽.° 提交于 2019-12-13 08:55:48
问题 I'm using the code bellow to run a few "netsh wlan" commands in order to check wifi status, connect to a wifi profile, etc. The problem that I'm having is that every now and then the app will hang on any of the commands, it's just a random thing, plus, sometimes the output returned get overwritten with "nothing", when I debugged it seemed like a timing issue. I tried the conventional approach to run a command with Pascal but it didn't work with netsh, the approach is "cmd.exe /C netsh wlan...

Pascal pointer to pointer SyntaxError and Incompatible types

喜夏-厌秋 提交于 2019-12-13 08:27:49
问题 Since there's no way to create refereces (is there?) I have to do it with a pointer to another pointer. This gives me an error: type PNode = ^TNode; TNode = record char: char; next: PNode; children: PNode; end; PPNode = ^PNode; var current_node: PPNode; function find_or_insert_peer(var node: PNode; character: char): PNode; current_node := @find_or_insert_peer(current_node^, character)^.children; x.pas(121,23) Error: Incompatible types: got "<address of function(var PNode;Char):^TNode;Register

Unsure tabbing with Pascal [closed]

给你一囗甜甜゛ 提交于 2019-12-13 08:03:12
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Hi I'm trying to tab some code, please could someone check to make sure I have done this correctly (Changed some code for simplicity): begin if Password <> Database['Database'] then showmessage ('Message') else if NewPassword <> Retype then showmessage ('Message') else begin

C# double to real

橙三吉。 提交于 2019-12-13 08:02:15
问题 i am trying to convert double to pascal real but when i convert 0.23 to real i got 0.23999999 real how can i truncate all 9999 to 0000. public static byte[] Double2Real48(double d) { byte[] r48 = new byte[6]; byte[] da = BitConverter.GetBytes(d); for (int i = 0; i < r48.Length; i++) r48[i] = 0; //Copy the negative flag r48[5] |= (byte)(da[7] & 0x80); //Get the expoent byte b1 = (byte)(da[7] & 0x7f); ushort n = (ushort)(b1 << 4); byte b2 = (byte)(da[6] & 0xf0); b2 >>= 4; n |= b2; if (n == 0)

How can I round an integer to the nearest 1000 in Pascal?

牧云@^-^@ 提交于 2019-12-13 05:43:52
问题 I've got a Integer variable in Pascal. Is there any possible function I can use that can round that value to the nearest 1000, for example: RoundTo(variable, 1000); Does anything of the sort exist? Or is there another method I should try using? Thanks! 回答1: The general solution for this kind of problem is to scale before and after rounding, e.g. y = 1000 * ROUND(x / 1000); 回答2: Use RoundTo(variable, 3) . The second parameter specifies the digits you want to round to. Since you want to round

Translating Python code for RC4 to Pascal

吃可爱长大的小学妹 提交于 2019-12-13 05:37:13
问题 I'm attempting to translate RC4 from Python to Pascal. This is the working Python code (not written by me): def KSA(key): key_length = len(key) S = list(range(256)) j = 0 for i in range(256): j = (j + S[i] + key[i % key_length]) % 256 S[i], S[j] = S[j], S[i] return S def PRGA(S, n): i = 0 j = 0 key = [] while n > 0: n = n - 1 i = (i + 1) % 256 j = (j + S[i]) % 256 S[i], S[j] = S[j], S[i] K = S[(S[i] + S[j]) % 256] key.append(K) return key key = 'Secret' plaintext = 'Attack at dawn' def

Are there good practices if any avoiding out of bounds index error when looping TStringList items?

狂风中的少年 提交于 2019-12-13 02:37:56
问题 :) First thing, my code procedure TForm1.Button3Click(Sender: TObject); var tempId,i:integer; begin tempId:=strtoint(edit5.Text); plik:=TStringList.Create; plik.LoadFromFile('.\klienci\'+linia_klient[id+1]+'.txt'); if (plik.Count=1) then begin label6.Caption:='then'; if (tempId=StrToInt(plik[0])) then begin Label6.Caption:='Zwrócono'; plik.Delete(0); end end else for i:=0 to plik.Count-2 do begin if (tempId=StrToInt(plik[i])) then begin Label6.Caption:='Zwrócono'; plik.Delete(i); end; end;

Reading from file FreePascal

这一生的挚爱 提交于 2019-12-13 02:31:06
问题 So I have text file containing: Harry Potter and the Deathly Hallows###J. K. Rowling###2007 And I have to output it to the FreePascal program in the following form J.K.Rowling "Harry Potter and the Deathly Hallows" 2007 year I know how to read from file but I don't know how to make it like in the previos form Can someone help me? I would be very thankful. 回答1: If TStringList in freepascal is the same as in Delphi, then this would do the trick: function SortedString( const aString : String) :