Lazarus error - how to store result of integer in textbox? - pascal

I'm trying out a very simple program in LAZARUS to multiply two text box values and store the result in a third one. This line is what I'm using.
txtA.Text = IntToStr( StrToInt(txtA.Text ) + StrToInt(txtB.Text) );
Unfortunately I get an error stating it's illegal.
Is this a fault on my part or a bug in Pascal?
Thanks for any tips!

The assigments in Pascal uses :=
try this
txtA.Text := IntToStr( StrToInt(txtA.Text ) + StrToInt(txtB.Text) );

I also tend to use IntToStr() also, but you also have the option of using format() - which is preferred for strings that might be translated.

Related

AHK: Using RandomBezier Function

I'm trying to use RandomBezier.ahk (https://github.com/MasterFocus/AutoHotkey/tree/master/Functions/RandomBezier) to randomize the mouse path to click on things in game.
The Example.ahk in that github works for me, but when trying to use it in my own program, it doesn't work when calling the RandomBezier function.
I have the files in the same local directory.
Any help on getting this function to work?
Thanks
#SingleInstance force
#Include RandomBezier.ahk
^j::
screenWidth := A_ScreenWidth
screenHeight := A_ScreenHeight
//I'm using ratios so that I'm not hardcoding based on a given display resolution
Play_X := floor(0.02604*A_ScreenWidth)
Play_Y := floor(0.37037*A_ScreenHeight)
RandomBezier(0, 0, %Play_X%, %Play_Y%, "T1200 RO RD OT100 OB-100 OL0 OR0 P4-3") //<-- this line doesn't do anything. the mouse doesn't move.
;MouseMove, %Play_X%, %Play_Y%, 10 <--this line works, so I know that the variables Play_X, Play_Y works
Sleep 50
Click
This is a classic mistake of trying to use legacy syntax in a place where it doesn't belong (though I'd argue it no longer belongs anywhere whatsoever).
Function parameters are passed in as expressions, not as legacy text parameters.
So instead of legacy way of referencing a variable
RandomBezier(0, 0, %Play_X%, %Play_Y%,,
you do
RandomBezier(0, 0, Play_X, Play_Y,.
Overall I'd recommend you to try to to get rid of legacy syntax. It's not 2008 anymore.
Reading this page on the documentation is a good start to learning the difference
https://www.autohotkey.com/docs/Language.htm

How to fill "waveInGetDevCaps" function parameters in Delphi?

I'm using the Window's API, in particular the 'WaveIn' functions. I want to know the format that my laptop's input audio device supports.
Therefore, I used the function "waveInGetDevCaps." This function call , once called, fills in a WAVEINCAPS structure with the information about the audio device.
This is my code so far:
procedure TForm1.Button4Click(Sender: TObject);
var
wc : WAVEINCAPS; // structure to be filled with audio device info
begin
waveInGetDevCaps(WAVE_MAPPER, &wc, sizeof(WAVEINCAPS));
Showmessage (wc.dwFormats);
end;
However I keep getting an error:
"E2010 Incompatible types: 'PWaveInCapsA' and 'tagWAVEINCAPSA2"
I would appreciate any help please.
Information on "waveInGetDevCaps" and "WAVEINCAPS" can be found:
https://msdn.microsoft.com/en-us/library/dd743841%28v=vs.85%29.aspx
https://msdn.microsoft.com/en-us/library/dd743839%28v=vs.85%29.aspx
You are using the wrong operator to take the address. You use & in C and C++. In Delphi the operator is #. This operator is documented here: http://docwiki.embarcadero.com/RADStudio/en/Expressions_(Delphi)#The_.40_Operator
In Delphi, & is used to escape keywords. It has no effect here, because wc is not a keyword, and is essentially ignored, treated as whitespace.
Replace & with # and your code will compile. Don't forget to check the return value of the function call for errors, as described in the function documentation.
The Delphi header translations introduce Pascal-case type names so instead of the WAVEINCAPS type it would be idiomatic to use the TWaveInCaps type.

Convert number to currency using Informatica

I'm trying to figure out the best way to convert numbers into currency using Informatica. For example, I want to convert 4000 to $4,000.00. I think the Java tx is the way to go but I have never used it and I'm unable to find examples of how to code it properly so that it works. Any help you can provide would be greatly appreciated.
Thank you,
Gary
Here is a solution in Expression Transformation without using Java. Of course, this is kind of static, but you can always code it for maximum possible amount.
v_AMT_STR := TO_CHAR(TO_DECIMAL(TO_CHAR(inp_AMT),2))
v_LEN := LENGTH(v_AMT_STR)
v_THSND_SEP := DECODE(TRUE,
IN(v_LEN,7,8,9), SUBSTR(v_AMT_STR,0,v_LEN-6)||','||SUBSTR(v_AMT_STR,-6),
IN(v_LEN,10,11,12), SUBSTR(v_AMT_STR,0,v_LEN-9)||','||SUBSTR(v_AMT_STR,-9,3)||','||SUBSTR(v_AMT_STR,-6),
IN(v_LEN,13,14,15), SUBSTR(v_AMT_STR,0,v_LEN-12)||','||SUBSTR(v_AMT_STR,-12,3)||','||SUBSTR(v_AMT_STR,-9,3)||','||SUBSTR(v_AMT_STR,-6),
v_AMT_STR)
o_CURRENCY := '$'||v_THSND_SEP
inp_AMT is decimal input port
v_ and o_ are variable and output ports respectively
It supports up to $999,999,999,999.99. You can add more lines in the DECODE above to go beyond that.

I need a data type big enough to hold pow(80,7)

Im using pow from cmath.h for the power of function. Im using the line of code pow(80,7). Int and long are to small to give me the right value. Im going to use printf or cout to display the result
what data type can I use
Maybe you should have a look at GNU GMP (https://gmplib.org/).
HTH!

Constant expression violates subrange bounds

I have a project that I'm going to rewrite to another language, and in order to do that - I'd like to build it. But when I try to build it, I receive "E1012: Constant expression violates subrange bounds".
I have such code:
var ForTolkResult : array[0..2000] of char;
ForTolkResult[sizeof(ForTolkResult)-1] := chr(0); // Occurs here
From my point of view everything is correct here, sizeof(ForTolkResult) = 2000 * 1, so sizeof(ForTolkResult) - 1 = 1999, that is in bounds of an array. (But I'm new to Pascal) So what's wrong here?
I'm trying to build it via Embarcadero C++ Builder. If this error is a bug in compiler, how can I turn this check off?
Does char really ocuppy one byte of memory? I mean, check whether it is an "Ansi" single-byte char and not a WideChar.
Anyway, when you need to access the last index of an array, you'd better use
ForTolkResult[High(ForTolkResult)] := chr(0);

Resources