Delphi cannot receive text from TEdit

I ran into a problem while writing code in Delphi. Namely, I can’t access the components, even if they are declared, and I used them in the code above (earlier in the procedures, now I try to use them in functions - maybe this is the reason, I don’t know, I'm not good at Delphi ) I made some screens to make them look clearer. Take a look.

http://imageshack.us/photo/my-images/90/weirddelphi1.png/

http://imageshack.us/photo/my-images/837/weirddelphi2.png/

http://imageshack.us/photo/my-images/135/weirddelphi3.png/ ">

As you can see on the first screen, I get a compiler error. It says that the component does not exist, but on the third screen you see that this component exists. On the second screen, I can even use this component (Code Completion can be called successfully, but if I try to call it in the secondFunction area, I get this error: “Could not cause code completion due to errors in the source code” - but what hell is a mistake?). If I comment on these two lines, which relate to Edit7 and Edit8, I can run the program without problems. I really cannot understand what is wrong, if any of you could give me some advice, it would be very helpful. I didn’t want to publish all the code here because it will take about 300 lines, but if you need to know something else to figure it out, then ask, I will tell you.

I do not have enough reputation points to place more than two hyperlinks, so you need to do “copy and paste” with the latter: D

+7
source share
1 answer

The problem is that Edit7 is part of the TForm1 class. Edit7 not available by name TForm1 . So you can use the global variable Form1 and do

 function secondFunction(x: extended): extended; var paramA, paramB: extended; begin paramA := StrToFloat(Form1.Edit7.Text); paramB := StrToFloat(Form1.Edit8.Text); Result := paramA + paramB * sin(x); end; 

or you can make secondFunction part of the TForm1 class:

 function TForm1.secondFunction(x: extended): extended; var paramA, paramB: extended; begin paramA := StrToFloat(Edit7.Text); paramB := StrToFloat(Edit8.Text); Result := paramA + paramB * sin(x); end; 

But then you need to declare secondFunction in the declaration of the TForm1 class, for example

 TForm1 = class(TForm) private { Private declarations } public { Public declarations } function secondFunction(x: extended): extended; end; 

at the beginning of the block.

+6
source

All Articles