|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a 狭くする window. With most browsers, 圧力(をかける)ing 加える, minus or 無 while the 支配(する)/統制する 重要な (ctrl) is held 負かす/撃墜する will change the texts size. (大きくする, 減ずる, 回復する to default, それぞれ.) (This is more fully explained, and there's another tip, at my 力/強力にする Browsing page.)
We're going to create an 使用/適用 which will put an arithmetic question on the 審査する. It won't complain if your answer isn't 訂正する, it will just wait for you to make it 権利. It will tell you you've (finally) got it 権利, and then give you (or your child!) another, and another, and another...
使用者s of the 使用/適用 will see...
Along the way, we are going to use variables, use an edit box, 令状 an event handler for the edit box's OnChange event, and use the built in 無作為の() 機能(する)/行事 (and it's 親族 randomize.)
We're going to 令状 the 使用/適用 really 不正に at first, the way a beginner would 令状 it. We'll look at what is so terrible about the "bad" 見解/翻訳/版, and then see how to create a 使用者 created 手続き to take the badness away.
At the end, we'll 追加する a little frill, to "演習" some of the programming knowledge acquired along the way.
Wow! I was trying to come up with a "little" 使用/適用, which would illustrate just one or two things. Don't worry, 非,不,無 of the above is ロケット/急騰する science, and all of them are 根底となる to Lazarus (and Delphi) programming, so while this tutorial may take a while to work through, by the end of it any beginners should have made 抱擁する strides に向かって Lazarus fluency.
For almost everything in this tutorial (the main exception has an explanatory 公式文書,認める at the 関連した 位置/汚点/見つけ出す), what you would do in Delphi would be the same. At this level, the tutorial is as good for Delphi learners as for Lazarus learners. (I 現実に "did" the tutorial, but under Delphi 4, to 実験(する) that 主張!)
Create a new 使用/適用...
If you can't easily 完全にする what is sketched in that 名簿(に載せる)/表(にあげる), may I please encourage you to run through my introduction to Lazarus programming tutorial? It will show you how, and introduce you to some other things I just 推定する you know.
Then use the 構成要素 palette....
...to 追加する a label on your form. (The label 構成要素 is the fifth one, the one with "Abc" on the icon.) Put it just below the "やめる" button already on the form, but on the left 手渡す 味方する of the form. (As you see it in the screenshot.)
Make the label's 指名する 所有物/資産/財産 "laQuestion", using the 反対する 視察官.
Now 追加する an edit box to the form. (The edit box is the sixth 構成要素 on the "基準 構成要素s" tab of the 構成要素 palette, the one with "ab" and the insertion point in a little box, the one with "TEdit" for its pop-up hint.) Put it just below the label you created a moment ago. Make the edit box's 指名する 所有物/資産/財産 "eAnswer".
That's it for the 構成要素s our form needs!
許す a little nostalgic ramble? I can 解任する in remarkable 詳細(に述べる) the first lesson I had in programming. Per Ranhoff, a monumental mathematics teacher, not to について言及する someone who as a boy helped 連合した fliers escape Nazi 占領するd Europe, had somehow, in 新規加入 to his normal workload, learned enough to show us how to use a PDP-8 computer. And in that first lesson he introduced us to variables.
A variable, as Per put it, is like a 地位,任命する office box. It is a place where you can put something. You can look at what is there. You can change what is there. 井戸/弁護士席... you can do these things once you know how the computer language you are working with creates and uses variables.
公式文書,認める that I said creates and uses. There are two things to master, before you will have variables in your repertoire.
Creating variables: We're now going to create two variables for our 使用/適用.
A moment ago, part of the code for our 使用/適用 looked almost like...
TLD002f1 = class(TForm)
buQuit: TButton;
eAnswer: TEdit;
laQuestion: TLabel;
私的な
{ 私的な 宣言s }
bNum0,bNum1:byte;
public
{ public 宣言s }
end;
I said "almost", because a moment ago, it didn't have the...
bNum0,bNum1:byte;
... line. 追加する it to what is on your 審査する.
That will create two variable: bNum0 and bNum1
Some ideas to take on board...
* Lazarus may 言及する to what you have created as "私的な fields". (They are 私的な fields! But the 補欠/交替の/交替する 称する,呼ぶ/期間/用語 "variable" is not so terrible as to make me eschew it.)
* Lazarus will 言及する to those 私的な fields by their 十分な 指名するs, e.g.: "LD002f1.bNum0". (That hierarchical "dot" 指名するing is tremendously powerful. Watch out for it, as you 進歩, but don't worry about it just now.
* There are many types of variables, and when a programmers 令状 about "types", they are using the 称する,呼ぶ/期間/用語 in a geeky and 明確な/細部 sense. The type of a variable... "byte" in the 事例/患者 we've just met... 決定するs the sort of thing which can and cannot be 蓄える/店d in the variable. In the 事例/患者 of a byte-type variable, we can 蓄える/店 whole numbers only, and only numbers in the 範囲 0-255, inclusive. We will 会合,会う another type すぐに.
* When we 追加するd "bNum0,bNum1:byte;" to our 使用/適用, we were "宣言するing" the variables. That is the 指名する for doing what it takes to make them 利用できる for the 使用/適用's code to use. The 宣言 is all about telling your compiler to 始める,決める aside some memory for 蓄える/店ing things... but don't worry about the 詳細(に述べる)s. You are creating the "地位,任命する office boxes" I spoke of earlier. Do not assume that you know what is in those boxes at the beginning, by the way. Always, somewhere, before you need to use the contents of a "box" (variable), put something in it "by 手渡す". Again, you will see that done in this tutorial.
* Use 論理(学)の 指名するs for variable. I could have called my variables "Peg" and "Fred"... the 使用/適用 would still run. But 論理(学)の 指名するs are best. I always start the 指名する of a byte-type variable with a "b". The next character is always an upper 事例/患者 letter. When I need two variables for 類似の 仕事s, the 指名するs are 類似の, with a digit 追加するd to the end. Computer programmers count from 無, hence the 指名するs bNum0, bNum1 as variables for 持つ/拘留するing some numbers in. The numbers we want 追加するd together by the 使用/適用's 使用者 will go in those variables.
WHEW!
Something you don't need to worry about for a while: Why did I put my new line in the "私的な" section, rather than the "public" section? That will only 事柄 when you start creating 使用/適用s with more than one 部隊... something that you don't need to do for やめる a while yet, if you are a beginner.
Put your mouse pointer over some part of the form that doesn't have anything on it (apart from the grid of dots), and 二塁打-click. The に引き続いて new text should appear in the Source Editor...
手続き TLD002f1.FormCreate(Sender: TObject); begin end;
Between the begin and the end, 挿入する...
laQuestion.caption:='Hi';
... and run the 使用/適用. The form should appear, and in place of laQuestion you should find "Hi".
What is going on?
The label 構成要素 we created and 指名するd laQuestion has a caption 所有物/資産/財産. When we 指名するd the 構成要素 "laQuestion", Lazarus changed the 初期の caption to "laQuestion" too. This is an example of setting a 所有物/資産/財産 at design time. I prefer to use the 構成要素's 指名する for it's 初期の caption, because then, while doing the programming, I can easily see what the 構成要素's 指名する is 単に by looking at it on the form.
When the 使用/適用 starts up, one of the first things it does is to put your form on the 使用者's 審査する. But just before it appears, if there is some code in a....
手続き TLD002f1.FormCreate(Sender: TObject); begin end;
... 封鎖する, then whatever is there is done. And, as you have seen, we can, for instance, change what is in the caption field of one of the 構成要素s on the form before the form (and its 選挙権を持つ/選挙人 構成要素s) appears.
By the way... do not try to create the text "手続き TLD002f1.FormCreate..." by typing it in by 手渡す. When you 原因(となる)d Lazarus to create that text, it did some other things behind the scenes.
The 創造 of the form is an event. Lazarus will do 確かな things behind the scenes whenever a form is created. If you want to 追加する to what happens at that time, you do it with code in the 封鎖する we have been discussing, which is the form's "OnCreate event handler".
Changing the caption of laQuestion was a trivial thing. Let's do something worthwhile. Alter the code in the event handler. Change it to....
手続き TLD002f1.FormCreate(Sender: TObject);
begin
bNum0:=5;
bNum1:=2;
laQuestion.caption:='What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?';
end;
Ah ha! I told you that variables should always be initialized, and here you see me initializing bNum0 and bNum1.
It's a pity that... for now... the question will always be "What is 5+2?". We'll 直す/買収する,八百長をする that. Later. After you've had your vegetables. Sorry.
Don't 行方不明になる a pesky little 詳細(に述べる) in the example above: When we want to put something in a variable (or change what is in a 所有物/資産/財産), we use two characters to say "becomes". The characters are the 結腸 and the equals 調印する... but don't think of it as "equals". Read the two together as "becomes". So, we have, above, "bNum0 becomes 5".
Moving 今後: A short time ago, we had a nice simple line...
laQuestion.caption:='Hi';
That nice concise 声明 means "The caption 所有物/資産/財産 of the 反対する "laQuestion" becomes 'Hi'".
The caption 所有物/資産/財産 can only strings, i.e. it can only 持つ/拘留する things of the "string" data type.
Anything between 選び出す/独身 引用する 示すs, e.g. 'Hi', is a string.
The long thing we created....
'What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?'
... "boils 負かす/撃墜する" to a simple string.
You can "glue" two strings together into a bigger string (the grown-up 称する,呼ぶ/期間/用語 is "concatenate") with the 加える 調印する. So...
'Hi'+'Earthling'
... is 同等(の) to...
'HiEarthling'
(If you want 'Hi Earthling', be sure to 追加する the space either after the Hi or before the Earthling... or...
'Hi'+' '+'Earthling'
... would be another way to do it.)
A digression for a 詳細(に述べる)...
If you have a long line of code, like our laQuestion.caption... line, and want to 分裂(する) the "論理(学)の" line across several lines on the 審査する, you can, in general. If you have a 論理(学)の line with a bit of string data, though, don't 分裂(する) the line in 中央の string. 分裂(する) it just after one of the + 調印するs, as I have done in the example. You can even...
sTmp:='分裂(する) a very long string into shorter ones.'; sTmp:='分裂(する) a very long '+ 'string into '+ 'shorter ones.'
... with 選び出す/独身 引用するs and 加える 調印するs.
支援する to work...
bNum0 is a byte-type variable. The caption 所有物/資産/財産 can only 持つ/拘留する string-type data. You can't say....
laQuestion.caption:=bNum0;
(Try that, to see what happens. You get a 収集する time error"... which is good! The 使用/適用 doesn't even start to run, because there is something "impossible" in your code. Better that the 使用/適用 doesn't run, than start, and then 落ちる over. Once you have all of the 収集する time errors out of some code, and you can run it, you then move on to the 段階 in which you アイロンをかける out the "run time" errors. In the 状況 of the 使用/適用 we are building, it would be やめる 平易な to build something that asked 使用者s "What is 5+2", but 扱う/治療するd "10" (5 times 2) as the "権利" answer. That would be a run time error. Sort of. It would, at least, be an error that you only 遭遇(する)d when the 使用/適用 was running. A more 狭くする 鮮明度/定義 of a run time error would be something that 原因(となる)s the 使用/適用 to "die", not 単に not do what you 手配中の,お尋ね者.)
ANYWAY... you can't say...
laQuestion.caption:=bNum0;
... because that's an 試みる/企てる to put some byte-type data into something that can only 持つ/拘留する string-type data.
Of course, the "answer" is 平易な. The に引き続いて, after you have initialize bNum0, is perfectly 合法的な...
laQuestion.caption:=IntToStr(bNum0);
... but, as you may have guessed, I will have to talk about it, even though it seems "obvious" what is going on. It is, if I may say so, "obvious" because of how you have been led gently to it. And if you take a minute to consider some points, the next thing I'm 主要な you to will be obvious, too.
IntToStr() is a 機能(する)/行事. It "boils something 負かす/撃墜する". In the 事例/患者 of....
IntToStr(bNum0)
The IntToStr 機能(する)/行事 "boils 負かす/撃墜する" what's inside the brackets, i.e. the ( ), into a string. We put the variable bNum0 inside the brackets. The computer "looked" inside the "地位,任命する office box", 設立する the number we had put there. It then changed the number into a string. The five we put into the variable, and the "5" which appeared on the 審査する might appear to be just a five, to you and me. But to the computer, 5-the-number, and 5-the-string are different, and we have to work with this reality.
Part of learning to work with any language is to learn about all of the marvelous 機能(する)/行事s which have been 供給するd for you by the creators of the language. And you will also be creating your own 機能(する)/行事s... やめる soon!
A 機能(する)/行事 is given some "成分s" and it returns a "result". The result is whatever you get when you 適用する some 支配する to the 成分s. In the 事例/患者 of IntToStr, the 機能(する)/行事 takes a number and returns a string. The 指名する comes from "(変える an) INTeger TO a STRing".
Just before we move on, look at our code again....
laQuestion.caption:='What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?';
You should now see that it more or いっそう少なく says...
laQuestion.caption:='What is '+'5'+
' 追加するd to '+'2'+'?';
We're just concatenating a bunch of short strings... but there's a little 魔法 in our actual code... what goes into the caption 所有物/資産/財産 in the 場所 of the 5 and the 2 depends upon what is in bNum0 and bNum1
Take a break. You've earned it. If you've really worked at the above, the next bit will be やめる 平易な.
We're going to create another variable, calling it sAnswer. This will be string-type data. And we will fill it with the answer to the question the 使用/適用 is asking the 使用者. (It is わずかに ironic, but perfectly 許容できる, that we don't 蓄える/店 the answer to the question, as a number, anywhere in the program! But we do 持つ/拘留する the string that the answer turns into if you change the answer (a number) into a piece of string-type-data.)
Up at the 最高の,を越す, where we have...
私的な
{ 私的な 宣言s }
bNum0,bNum1:byte;
... 追加する a line, making it...
私的な
{ 私的な 宣言s }
bNum0,bNum1:byte;
sAnswer:string;
And now, 負かす/撃墜する in the FormCreate 手続き, just before it's "end", 追加する....
sAnswer:=inttostr(bNum0+bNum1);
If bNum0 持つ/拘留するs 5, and bNum1 持つ/拘留するs 2, as they do, at the moment, then after the line above, the string sAnswer will 持つ/拘留する 7... as a string, not as a number.
That wasn't hard!
Now we will turn to how to get 使用者s to "tell" the computer they think 5+2 comes to. And check the 使用者's answer against what is in sAnswer.
耐える with me a little... we have to go out on some thin ice, but if you keep your wits about you, I'll keep you 安全な until the ice grows 厚い, as you begin to understand how everything 作品.
Way 支援する when we started, you put an edit box on the form.
If you run the 使用/適用, you will find that you can already type things into the edit box.
追加する a line to the form's OnCreate handler 説...
eAnswer.text:='';
(That's two 選び出す/独身 引用するs, not one 二塁打 引用する.)
That line says "make the eAnswer 構成要素's text 所有物/資産/財産 持つ/拘留する nothing, make it empty". The 所有物/資産/財産 called "text" is an edit box's 見解/翻訳/版 of the 所有物/資産/財産 called "caption" in a label.
Stop the 使用/適用, if you have it running. Go 支援する into the design 明言する/公表する. 二塁打 click on the edit box, and you should get the に引き続いて in your Source Editor...
手続き TLD002f1.eAnswerChange(Sender: TObject); begin end;
The 二塁打 click has told Lazarus that you want to create a handler for the most 一般的に used event of the 構成要素. I've put "event" in bold italics, because events are 決定的な to Windows and Linux programming. We'll talk about it later, for now we will just use it.
Change the above to....
手続き TLD002f1.eAnswerChange(Sender: TObject);
begin
if eAnswer.text=sAnswer then begin
showmessage('権利!');
end;
end;
Run the 使用/適用, play with it a bit. Each time the contents of eAnswer is changed to 7, the answer to our question, the "権利" message pops up.
Wow!
So far, so good.
To "take it to the next level", you need to know about the built in 無作為の() 機能(する)/行事.
取って代わる the lines in the FormCreate handler which say...
bNum0:=5; bNum1:=2;
... with...
bNum0:=無作為の(10); bNum1:=無作為の(10);
Also, just before them, 追加する a line that says...
randomize;
The first line, "bNum0:=無作為の(10);", will 原因(となる) a number to be put into bNum0... but you won't know what the number will be! But it will be an integer, in the 範囲, 0-9 (nine) inclusive. 厳密に speaking, it won't be a "無作為の" number... but for many, many 目的s, it will be as good as 無作為の.
The second line puts a 無作為の number in bNum1. (A different 無作為の number 9 times out of 10, though from time to time... 無作為に!... the same number will be "drawn out of the hat" for both of them.)
The other line we 追加するd, "randomize;", is connected with my 資格 above, about the number not 存在 truly 無作為の.
Without the randomize, which you only need to put in the 使用/適用's code once, before the first call of 無作為の(), you would get the same sequence of "無作為の" numbers each time you ran the 使用/適用! Getting the same sequence can be helpful, if you are debugging something. To get the same sequence each time, just take out the randomize 声明. Different sequences are usually best in finished 使用/適用s. Just put the randomize 支援する!
Play with that a bit.
罰金. As long as you don't mind 再開するing the 使用/適用 again and again, to get different questions. Have a little think... can you see how to get a different question each time you answer the previous question 正確に? Don't scroll 負かす/撃墜する until you tried to think of answers for yourself... the answer is just below here...
Look again at the handler for the OnChange handler of the edit box, eAnswer. That code 遂行する/発効させるs every time what's in the edit box changes, which, in this 使用/適用, happens when a 使用者 enters something on the keyboard, 含むing the "削除する" or "backspace" 重要なs, etc.
手続き TLD002f1.eAnswerChange(Sender: TObject);
begin
if eAnswer.text=sAnswer then begin
showmessage('権利!');
end;
end;
You will 徐々に learn to see Pascal code in "封鎖するs". What we have above, at the highest level, is...
手続き TLD002f1.eAnswerChange(Sender: TObject); begin (SOMETHING) end;
The "something" is....
if eAnswer.text=sAnswer then begin
showmessage('権利!');
end;
That something can be seen as....
if eAnswer.text=sAnswer then begin
(ANOTHER THING)
end;
... with "another thing" 存在
showmessage('権利!');
With a small snippet of code like that, the above 分析 is a long way "over the 最高の,を越す", but try to しっかり掴む the 概念. Looking at an 使用/適用 with 1500 lines of code without those techniques won't get you very far. Also try to 令状 your code with the 封鎖する structure in mind. (It will help you 令状 code which will 収集する!)
The begins and ends in the above are important to the structure of the code. I can't "tell you all about" begins and ends.. the 概念s behind them will be something you 徐々に master as you work through programming 仕事s.
For now, look closely at....
if eAnswer.text=sAnswer then begin
The "then" in that has nothing to do with time. It is all about consequences, e.g. "If you play with 解雇する/砲火/射撃, THEN you will get 燃やすd."
And the handler for the OnChange event is where we need to 追加する some code, if we want our 使用/適用 to behave sensibly. Make the handler's code....
手続き TLD002f1.eAnswerChange(Sender: TObject);
begin
if eAnswer.text=sAnswer then begin
showmessage('権利!');
bNum0:=無作為の(10);
bNum1:=無作為の(10);
laQuestion.caption:='What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?';
sAnswer:=inttostr(bNum0+bNum1);
eAnswer.text:='';
end;
end;
Notice that the "new" stuff is all inside the begin / end 封鎖する which is 遂行する/発効させるd when eAnswer.text does equal sAnswer. I.e. what is in the text 所有物/資産/財産 of the eAnswer edit box (which 使用者s can change, just by typing) is the same as (equals) what you 蓄える/店d in the variable sAnswer when you 選ぶd new numbers for the question.
Re-read that last paragraph. What it says is intuitively obvious, I hope. I worked やめる hard on it to use 条件 井戸/弁護士席, so that you will be able to understand what I say later, when I am explaining something that is not so obvious. Master the jargon.
Fresh cup of coffee in 手渡す? Good! Onward.
What come next may seem off-手渡す, a 詳細(に述べる), but it isn't. If you can しっかり掴む what it is about, you'll make a leap 今後 in your programming competence.
So far we have something that "作品". Good?
Not good. It is 不正に written. And 不正に written 使用/適用s always "落ちる over" 結局, they are hard to 修正する, etc, etc, etc. They will bring the fleas of a thousand caravanserai to your home.
What's so terrible about that code? What's "terrible" is that we've written the に引き続いて out twice...
bNum0:=無作為の(10);
bNum1:=無作為の(10);;
laQuestion.caption:='What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?';
sAnswer:=inttostr(bNum0+bNum1);
At the moment, it appears as part of FormCreate AND as part of PrepareQuestion.
You should always be nervous if you 令状 something twice. What happens if you need to make a change. Suppose, for instance, you want to 修正する the program so that it asks multiplication questions instead of the 新規加入 questions it asks now? (The 調印する for "multiply" is *, by the way. You might like to try making the change, either now or later. If you've really understood what is in this tutorial, the changing isn't hard at this 行う/開催する/段階, and will be really 平易な by the time we've "直す/買収する,八百長をするd" the Bad Programming.)
It also saves you typing! (Even if you are good at copy/paste, Doing It With 機能(する)/行事s is Just Better.)
以前, we've seen the 無作為の() 機能(する)/行事. We've seen the IntToStr() 機能(する)/行事. Each "returns" something to you, something based on what you sent to the 機能(する)/行事 inside the brackets.
You've also seen 手続きs, although I 港/避難所't used the 称する,呼ぶ/期間/用語 before now. You've seen showmessage(), you've seen randomize
A 手続き does something for you. It doesn't "return a result", the way a 機能(する)/行事 does. You might think that showmessage() returns a result, because it puts your message on the 審査する, but that sort of thing doesn't count. You are only returning a result if the 機能(する)/行事 call "boils 負かす/撃墜する" to a new datum, something that can go into a variable, for instance. Or into a 所有物/資産/財産 of some 構成要素.
Not only does Lazarus come with a bunch of 手続きs (and 機能(する)/行事s), but you can make your own. (手続きs, or 機能(する)/行事s.) We're going to use that 能力 now.
Up 近づく the 最高の,を越す of the program, we 宣言するd 3 variables...
私的な
{ 私的な 宣言s }
bNum0,bNum1:byte;
sAnswer:string;
Make that...
私的な
{ 私的な 宣言s }
bNum0,bNum1:byte;
sAnswer:string;
手続き PrepareQuestion;
And just before the "end." at the end of the code... ("end." with a 十分な stop, period, notice. Not a semicolon for once)... 追加する...
手続き TLD002f1.PrepareQuestion;
begin
bNum0:=無作為の(10);
bNum1:=無作為の(10);
laQuestion.caption:='What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?';
sAnswer:=inttostr(bNum0+bNum1);
eAnswer.text:='';
end;
(I'll go through that in a moment.)
Look familiar?
Now, in the two old places where you had...
bNum0:=無作為の(10);
bNum1:=無作為の(10);
laQuestion.caption:='What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?';
sAnswer:=inttostr(bNum0+bNum1);
eAnswer.text:='';
... 取って代わる just that much, twice, with...
PrepareQuestion;
That, for my Lazarus readers, will make the whole thing what you see below. There are a few differences in the first few lines for my Delphi readers... but those lines were created by Lazarus or Delphi, and I 港/避難所't told you to tinker with them, have I?
(The 最高の,を越す of the Delphi would look like...
部隊 LD002u1; interface uses Windows, Messages, SysUtils, Classes, Graphics, 支配(する)/統制するs, Forms, Dialogs, StdCtrls; type TLD002f1 = class(TForm)
The Lazarus code is...
部隊 ld002u1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, 支配(する)/統制するs, Graphics,
Dialogs, StdCtrls;
//These are the 部隊s a Windows 使用者 will see. I'm told
//that いつかs Linux 使用者s won't have "FileUtil" here.
type
{ TLD002f1 }
TLD002f1 = class(TForm)
buQuit: TButton;
eAnswer: TEdit;
laQuestion: TLabel;
手続き buQuitClick(Sender: TObject);
手続き eAnswerChange(Sender: TObject);
手続き FormCreate(Sender: TObject);
私的な
{ 私的な 宣言s }
bNum0,bNum1:byte;
sAnswer:string;
手続き PrepareQuestion;
public
{ public 宣言s }
end;
var
LD002f1: TLD002f1;
実施
{$R *.lfm}
{ TLD002f1 }
手続き TLD002f1.buQuitClick(Sender: TObject);
begin
の近くに;
end;
手続き TLD002f1.eAnswerChange(Sender: TObject);
begin
if eAnswer.text=sAnswer then begin
showmessage('権利!');
PrepareQuestion;
end;
end;
手続き TLD002f1.FormCreate(Sender: TObject);
begin
randomize;
PrepareQuestion;
end;
手続き TLD002f1.PrepareQuestion;
begin
bNum0:=無作為の(10);
bNum1:=無作為の(10);
laQuestion.caption:='What is '+inttostr(bNum0)+
' + '+inttostr(bNum1)+'?';
sAnswer:=inttostr(bNum0+bNum1);
eAnswer.text:='';
end;
end.
冷静な/正味の? If you 約束 to come 支援する and finish the tutorial, you can take a break by trying to change the 使用/適用 so that it will give multiplication questions
We've just created our own 手続き. I want to tell you some of the things that have to be done 権利:
The 手続き 指名する should be put together like a variable 指名する: Start with a letter, use only letters and digits. Make it 述べる what the 手続き does.
A little "gotcha": Don't use a 指名する that Lazarus already uses, like ShowMessage. But it's a gotcha, '原因(となる) you don't know all the 手続きs, do you? And the "worse news"? Lazarus won't complain if you do "再生利用する" one of the 指名するs it knows... it will just 行為/法令/行動する weird if you try to use the built-in 手続き and your 手続き of the same 指名する.
A 詳細(に述べる): in the "私的な" 封鎖する, where you 宣言する your variables and 手続きs (and, in 予定 course, 使用者-created 機能(する)/行事s), do all of the variable 宣言s before you do any 手続き or 機能(する)/行事 宣言s. (The latter two can be all jumbled up, though.)
You can stop reading here.
It really would be best if you were to build the 使用/適用 by working through the text above, but if you have tried, and it Just Won't Work, and you are wondering if your Lazarus isn't 任命する/導入するd 適切に, you can download a zip とじ込み/提出する with everything in it. Just unzip the contents of the とじ込み/提出する to a folder, any (empty) folder, 二塁打-click on the .lpi とじ込み/提出する, and you should have everything you need. (On a machine with no Lazarus 取り付け・設備, you can still use the LD002.exe とじ込み/提出する.)
Just for the 演習, I'm going to 延長する the 使用/適用 just a little bit. I want to 陳列する,発揮する how many times eAnswerChange is called, in hopes of impressing you with...
Put a new label on the form. Call it laCalls
In the FormCreate 手続き, 追加する...
laCalls.caption:='';
宣言する a new variable. The に引き続いて should go just after the "sAnswer:string;" we already have
wCalls:word;
(A "word" type variable can 持つ/拘留する integers in the 範囲 0-65535, inclusive)
追加する "wCalls:=0;" to the FormCreate 手続き.
In the eEdit OnChange handler, make the changes you see in this 完全にする 名簿(に載せる)/表(にあげる)ing of the new handler...
手続き TLD002f1.eAnswerChange(Sender: TObject);
begin
wCalls:=wCalls+1;
laCalls.caption:=inttostr(wCalls);
if eAnswer.text=sAnswer then begin
showmessage('権利!');
PrepareQuestion;
end;
end;
That's it!
Just notice that the new stuff is before the if... then... part. It will happen every time the eAnswerChange 手続き 遂行する/発効させるs.
One little thing which you should have noticed, may wonder about... What on earth is...
wCalls:=wCalls+1;
... all about? Your algebra teacher would not be impressed!
But then again, he doesn't know to read it as "wCalls becomes wCalls 加える one".
The = 調印する is 単に part of the two character "word" ":=". We are NOT 説 "wCalls EQUALS wCalls+1".
What we are 説 is....
"In the wCalls variable after this line is finished, we want what was in it before, with one 追加するd. I.e. "wCalls BECOMES the old contents of wCalls, 加える one."
I've spend a good chunk of two days typing the first 草案 of this tutorial and the one for LD001. If you are new to programming, you have worked very hard to get this far. But, and I really mean this, if you have really concentrated, not gone "yeah, yeah" too often, then the 支援する of "becoming a programmer" is broken. Yes, you do still have things to learn. But things will move much more quickly from here.
|
|
If you visit 1&1's 場所/位置 from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service. They 申し込む/申し出 things for the beginner and the 会社/団体.![]()
Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.
. . . . . P a g e . . . E n d s . . . . .