|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
This tutorial shows you several useful tricks in a somewhat 人工的な 状況. You can read it for those tricks, or you can tweak what is 現在のd to turn it into something 演説(する)/住所ing needs you have.
It is not a short tutorial, but it is one I 特に commend to you. For a start, I've lavished more 編集(者)の time on it than on a typical tutorial. It covers several points of general use and importance. I wrote it a long time after beginning the tutorials series, and you get the 利益 of the hours I've spent working with Delphi since 令状ing some of the 早期に tutorials.
Beware of getting half way though and thinking, "Okay, I've got that." Several new things 刈る up later in places you might not 心配する them.
This page revisited 10 損なう 23, bits tweaked.
支援する in September 2006, I said that I thought this tutorial was one of the better ones in my Delphi series. 2016, I was still 説 that, even if it is a bit out of the ordinary. It doesn't chase a particular goal, but some useful techniques arise along the way. I believe that making the 成果/努力 to go through this will 強化する your programming 技術s. 2023-I'd commend you to Lazarus, but this page is still one I 言及する to myself, to help me with the 詳細(に述べる)s of a useful "string" for your Delphi or Lazarus program 開発.
In July 2016, I worked through the tutorial, trying to do what it says, but using Lazarus. There were remarkably few things which didn't work 正確に/まさに as they do in Delphi, and 非,不,無 needed major re-workings to make the operate 適切に. 2023: I am, of course, 7 years older. I must have been taking stupid pills. I had trouble 追加するing to pages to a 事業/計画(する), and I can't even tell you why. I just kept coming 支援する to this, trying to do what it says. Be sure you do a "save all", and then use とじ込み/提出する Explorer to make a copy the whole folder. I usually append "BUyymmdd" to the folder's 指名する each time I do that. You DO need to do the Save All inside the Lazarus IDE before you make the backup, but you don't need to の近くに your Lazarus 開会/開廷/会期. I 信用 you keep a...
const vers='[[date/time stamp]]';
... in your code, and remember to 改訂する the date/time stamp at the necessary times?
My experience 一般に of "変えるing" things to Lazarus from Delphi is that it will 普通は go very 井戸/弁護士席. Even where the text below is 明確に speaking of what you do if programming with Delphi, assume it is the same if programming with Lazarus unless there are 指示,表示する物s to the contrary.
The tutorial covers having 多重の forms in an 使用/適用, and it covers passing Delphi 支配(する)/統制するs to subroutines. It also illustrates using boolean variables to manage the 外見 of a form. The way they are going to be used means that different things can happen at different times... times the programmer can neither 心配する nor 支配(する)/統制する. If you are a dinosaur programmer, who started 支援する in the days of structured programming, and who is used to sequential 死刑執行, there are some wonderful things you can do in event driven programs that just can't be done "the old ways". Here you can learn about doing those things. If you aren't from "the good old days", you may not even see that what we're going to do is wonderful... but it is!
The tutorial arose from an 使用/適用 I wrote in 関係 with my FarWatch system. FarWatch costs nothing more than having an always-on internet 関係. It doesn't have to be a static IP 演説(する)/住所. With it, you can 監視する a 場所 across the internet. The simple FarWatch 単に puts a page of (警察などへの)密告,告訴(状) on the 逮捕する for anyone to check. The 使用/適用 that this tutorial derives from automatically reads that page from time to time, and 陳列する,発揮するs 報告(する)/憶測s for the 使用者. The 報告(する)/憶測s are 陳列する,発揮するd where ever the FarWatch 監視するing program is running, which can be on any internet connected Windows PC. The 報告(する)/憶測s are only on-審査する messages at the moment, but it would be 比較して 平易な to hook the computer up to an alarm bell which could be made to (犯罪の)一味.
The 報告(する)/憶測s (seen at the place where the FarWatch 監視するing program is running) come in two flavors: Alarms and 警告s. A 警告 might be "The watched house's 気温 has fallen to 50 degrees F." Bad news, but not 価値(がある) (犯罪の)一味ing an alarm bell at 3am! An alarm might be "The 侵入者 detector 報告(する)/憶測s someone in the house." or "The house's 気温 is now 35° F and 落ちるing. The water 麻薬を吸うs may 凍結する soon." 価値(がある) (犯罪の)一味ing that bell, even at 3am!
In this tutorial, instead of looking at a FarWatch page, the program will 単に look at a scrollbar 反対する. If its "position" 所有物/資産/財産 returns a low enough value, there will be neither 警告 nor alarm. If the thumb tab is higher, a 警告 will arise. If it is very high, an alarm will arise. In either 事例/患者, the program will return the slider to the "no 警告/ no alarm 明言する/公表する" when it (悪事,秘密などを)発見するs either. (This to 妨げる 多重の 警告s/ alarms.) You could re-program the 使用/適用 to watch different inputs. Connecting things through a 平行の port is explained on my 平行の port page. (I also have a serial port (警察などへの)密告,告訴(状) page.)
Inside the zip とじ込み/提出する with the Delphi 見解/翻訳/版 of the 事業/計画(する)'s source code, you will also find the exe. This would be a good time to run that, to get an idea of where we are going. (It won't "do things" to your system, e.g. 令状 to your registry. Or 接触する the internet.) Move the scrollbar's thumb tab to half way across; 解放(する) the mouse button. Move the thumb tab again, this time all the way to the 権利.
You can download a .zip とじ込み/提出する with the sourcecode. The zip also has an .exe とじ込み/提出する in it, which, as with the Windows 見解/翻訳/版 of the program can be run 直接/まっすぐに from the .zip... although it takes a few seconds to appear, because of all that has to happen. (Nothing is 任命する/導入するd on your machine, but it takes a bit of time to 抽出する a scratch copy of the code from the .zip) Everything in the .zip comes from a 開会/開廷/会期 on a Win7 machine running the 32-bit Lazarus, 見解/翻訳/版 1.0, of 28Aug2012.
What I've 述べるd above could be 遂行するd many ways, all of which would look the same to the 使用者. One 示す of a 井戸/弁護士席 designed program is that it is 平易な to 修正する it. I hope the tutorial's program 落ちるs into that 部類. If so, all sorts of refinements are 比較して 平易な. Take, for instance, the alarm bell. In a simple 使用/適用, it would (犯罪の)一味 whenever an alarm 条件 存在するd. In a fancy program, it could be make to (犯罪の)一味 簡潔に once in a while IF the time of day was between 8am and 10pm, AND there a 警告 条件 存在するd.
If the program is 井戸/弁護士席 designed, a その上の frill should be 平易な to 追加する: It should be possible for the hosting computer to go into a 監視する-off 代替要員,物 方式, but wake if there is a 警告 or alarm. See the screensaver 言及/関連 in the (米)棚上げする/(英)提議する of contents of my tutorials if you want to 器具/実施する this frill.
And so on! One of the 広大な/多数の/重要な joys of programming is that the only 限界 is your imagination!
The 使用/適用 will have three forms.
The main form will have sundry buttons and 陳列する,発揮するs. The other two forms will each have a 覚え書き. One will 陳列する,発揮する the 警告s the 使用/適用 has seen, and the other will 陳列する,発揮する the alarms. It is 比較して 平易な to 延長する the 使用/適用 to 記録,記録的な/記録する the 警告s and alarms in data とじ込み/提出するs, should you want that frill.
Start a new 使用/適用. Under Delphi, I called this 使用/適用 DD68 (68th Delphi デモ). 指名する the form DD68f1.
For Lazarus, call the 使用/適用 LD68. (Lazarus 見解/翻訳/版 of delphi デモ number 68.) 指名する the form LD68f1.
Save what you have already. Under Lazarus, create a folder called LD68 where ever you want it, save the .lpi とじ込み/提出する as LD68 inside that folder. Save the .pas とじ込み/提出する as LD68u1.pas. If you want to eschew upper 事例/患者 letters, I don't think it will 事柄... so long as you do so 終始一貫して. (And at some levels, Lazarus will just ignore you, 軍隊 all lower 事例/患者, anyway! Or maybe 地雷 is doing that because of some system setting I 受託するd a while ago. I half remember something about Lazarus not 存在 happy with mixed 事例/患者 in とじ込み/提出する 指名するs because in Linux, MyFile.txt and myfile.txt are two different とじ込み/提出するs, and so doing everything in lower 事例/患者 is a Good Practice. Even though I, and maybe you, use Lazarus under Windows, it is a multi-壇・綱領・公約 language, and has to worry about things that people who only use Windows don't have to. (Don't have to worry about.))
Put a scrollbar on the main form. This is just a quick, 平易な, uncomplicated source of 人工的な alarm and 警告 条件s. Leave everything at their default settings. (Those should 含む: Position=0; Min=0; Max=100) (事業/計画(する) developed using Delphi 2. There is nothing "clever" in this that should not work in later 見解/翻訳/版s of the IDE.) (This paragraph needed no edits to be "権利" for Lazarus v1.0, 32 bit, on a Win7 machine, 12 July 16.)
Put a timer on the main form. If the scrollbar was going to be what we 手配中の,お尋ね者 to use in a real 使用/適用, we wouldn't need this timer, but for most things, you will want to use a timer. It lets you check things periodically, without having to depend on anything else to 誘発する/引き起こす the check. Again, the default 所有物/資産/財産 values are 罰金.
Re-save your work.
二塁打 click on the timer, to open the OnTimer event handler. Make it...
CheckAndHandleAlarmsOrWarnings;
Within the 私的な part of the TDD68f1 class 宣言, 追加する....
手続き CheckAndHandleAlarmsOrWarnings;
Just before the final "end." of DD68u1.pas/ LD68u1.pas, 追加する....
手続き TDD68f1.CheckAndHandleAlarmsOrWarnings;
begin
if scrollbar1.position>60 then begin
scrollbar1.position:=0;
showmessage('Alarm!!');
end;
end;
... save, and try to run what you have so far.
If you are using Lazarus, and you get "ld68u1.pas(40,19) Error: Identifier not 設立する "TDD68f1" ", don't be alarmed... I deliberately 始める,決める you up to fail!
If you are using this tutorial with Lazarus, there will be many, many places where you have to make a 確かな tweak to things you will see here.
If, here, it says...
追加する... 手続き TDD68f1.CheckAndHandleAlarmsOrWarnings; begin if scrollbar1.position... ... to your code
... then you will need, every time, to change the TDD68 to TLD68.
Make that change to the start you have made, and now you should find that it "作品"....
You should (結局... the first 収集する いつかs takes a little while... 40 seconds, not 20 minutes!)...
You should, as I was 説, get a window with a "working" scroll 妨げる/法廷,弁護士業 in it.
Not much happens when you move the scrollbar... But if you CAN move the scrollbar thumb thing more than 60% of the way to the 権利, you should get a message 説 "Alarm!".
After the ....
showmessage('Alarm!!');
end;
....you just 挿入するd, but before the 手続き's "end;", 追加する....
if scrollbar1.position>30 then begin
scrollbar1.position:=0;
showmessage('警告!!');
end;
Now you should also get a reaction to moving the thumb above the 30% position. 公式文書,認める that you will いつかs get a "警告" during the instant you are moving the thumb tab up to an "Alarm" 明言する/公表する. This is just a quirk of the way we are 生成するing 警告s and alarms. It occurs if the timer event happens at the 正確な moment that you are moving the thumb tab through the "警告" zone. Real sources of 警告s and alarms are not likely to behave thus.
公式文書,認める also that we are setting the scrollbar position 支援する to 無 whenever there is an alarm or 警告. This is somewhat 人工的な, but it saves you getting 多重の alarms and 警告s after changing the scrollbar's position 所有物/資産/財産.
Before we go 支援する and 精製する the 警告 and Alarm 扱うing, we are going to make separate forms (windows) to 持つ/拘留する スピードを出す/記録につけるs of the 警告s and alarms received to date. Each window will have a 覚え書き on it for that 職業. The 覚え書きs could be on the main form, but it isn't as 平易な to manage them if they are there. As separate windows, 使用者s can put them where they wish.
(新規加入, 2023: The に引き続いて speaks of 追加するing two forms in one pass. If you have any trouble, step 支援する to trying to do them one at a time.)
Delphi: Click とじ込み/提出する | New | Form (Click 承認する)... twice. Re-save the 事業/計画(する), calling the new 部隊s DD68uWarnings and DD68uAlarms.
Lazarus: Click とじ込み/提出する | New Form ... twice. Re-save the 事業/計画(する).
(新規加入 of 2023... when I was using Lazarus v2.0.0 r60307 and Windows 10...
Be careful about what 指名する goes where. Of course you need to be careful with the "DD68fWarnings"/"DD68fAlarms" part, but asl be careful about the "u" or "f" (or neither!) at the ends of the 指名するs.
Calling the new 部隊s DD68uWarnings and DD68uAlarms.
You will probably want to move things about a bit, to make them 平易な to get to in the clutter of windows on your 審査する. In Lazarus, if you can't see one of the forms, go to the source editor, click on the form's tab, 圧力(をかける) F12. (Something の近くに to that 作品 in Delphi, too.)
At this 行う/開催する/段階, under Lazarus, I had a bit of a struggle to move the 反対する 視察官 between the different forms. (2023: Ineptitude 固執するs.)
If I went to the Source Editor, selected the form I 手配中の,お尋ね者 to work with, and then 圧力(をかける)d F12, to bring up the 陳列する,発揮する of the GUI 反対する we were building, then the 反対する 視察官 switched to that 反対する.
指名する the forms DD68fWarnings and DD68fAlarms, put a 覚え書き on each, resize and reposition both form and 覚え書き so that all three forms are 明白な.
You will need StdCtrls in the Uses 条項 of each form. If the system doesn't 追加する it automatically when you 追加する the 覚え書き to the form, do it by 手渡す. (My thanks, and your thanks, to the Gentle Reader who kindly wrote in to point that out.) (I'd be 利益/興味d: Was it 追加するd automatically when you were doing the 演習? Delphi or Lazarus? 見解/翻訳/版? OS?)
(July 16: Win7, Laz 1.0: The StdCtrls 言及/関連 was 追加するd to the Uses 条項s when I put the 覚え書きs on the forms. Also 2023.)
Check that the "明白な" 所有物/資産/財産 of the two new forms is 始める,決める "true", using the 反対する 視察官 (Open with F11. Lazarus: Be sure you are looking at the 反対するs/ 所有物/資産/財産s of the form you mean to be... remember that getting the 反対する 視察官 to switch its attention to the 権利 form isn't (to me, anyway) 完全に intuitive.)
We want now to put something in the FormCreate handler of each of the new forms.
If an "empty" FormCreate doesn't 存在する on one or the other, just 二塁打-click on the form to 供給する yourself with one.
追加する to it...
memo1.(疑いを)晴らす;
Just for the sake of going a step at a time, in DD68u1/ LD68u1, just before "showmessage('警告!!');" 追加する....
DD68fWarnings.memo1.lines.追加する('Hello Window!');
Save everything. Run the 事業/計画(する).
When you try to run the 事業/計画(する), you'll be told....
Delphi: "Form DD68f1 言及/関連s DD68fWarnings" ((Ummm.. or is it DD68uWarnings?? One or the other! Check carefully what you see on 審査する. I noticed this possible error when 令状ing the Lazarus 見解/翻訳/版.))
Lazarus: ld68u1.pas(48,21) Error: Identifier not 設立する "LD68fWarnings"
Delphi asks...
"Do you wish to 追加する it [to your USES 条項]"
Say yes.
For Lazarus, you go to the Uses 条項 of LD68u1, and 追加する LD68uWarnings to the 名簿(に載せる)/表(にあげる). (By 手渡す)
N.B.: The 警告 speaks of not 存在 able to find LD68f警告s, but you 追加する LD68u警告s to the Uses 名簿(に載せる)/表(にあげる). This is because LD68f警告s is created within LD68u警告s.
By the way... when I tried to do all of the above, when I got to the part just covered, I 設立する that somehow the two 部隊s with 覚え書きs had somehow been saved as DD68... instead of LD68. A quick "Save As" for each of them was all it took to 始める,決める things 権利. Did you find they were DD68... too? Maybe I just didn't follow my own 指示/教授/教育s closely enough.
What have we done by that?...
Move the scrollbar's thumb tab up into the "警告" zone, and look for the "Hello Window" that should appear (along with the as-before Showmessage 生産(高).)
===
Pause for breath.
===
Don't worry about "Why do it that way? You could also...." Yes! I know! (For instance, the 覚え書きs could be on the main form. You'd just have to give them different 指名するs.) This tutorial isn't trying to show you "the" way to 監視する some alarm system. It is 単に illustrating some things.
===
Moving on.
===
We're now going to "divide", in hopes of "征服する/打ち勝つing". For the moment, in 尊敬(する)・点 of what follows.... "Just do it!" At first it may seem pointless, but when you get to "Review the above", review what you've done, looking 支援する to be sure you understand all that has happened.
The first changes below are 単に the first steps along a path.
===
Within the 私的な part of the TDD68f1 class 宣言, 追加する....
手続き ReactToWarning;
... and change the 底(に届く) part of your program. 公式文書,認める that you will be re-doing bits of CheckAndHandle in 新規加入 to 追加するing new stuff. Make the last part of your program....
DELPHI:
手続き TDD68f1.CheckAndHandleAlarmsOrWarnings;
begin
if scrollbar1.position>60 then begin
scrollbar1.position:=0;
showmessage('Alarm!!');
end;
if scrollbar1.position>30 then ReactToWarning;
end;
手続き TDD68f1.ReactToWarning;
begin
scrollbar1.position:=0;
DD68fWarnings.memo1.lines.追加する('Hello Window!');
showmessage('警告!!');
end;
end.
LAZARUS: (The only difference is the DDs have been changed to LDs)
手続き TLD68f1.CheckAndHandleAlarmsOrWarnings;
begin
if scrollbar1.position>60 then begin
scrollbar1.position:=0;
showmessage('Alarm!!');
end;
if scrollbar1.position>30 then ReactToWarning;
end;
手続き TLD68f1.ReactToWarning;
begin
scrollbar1.position:=0;
LD68fWarnings.memo1.lines.追加する('Hello Window!');
showmessage('警告!!');
end;
end.
Save and run the 事業/計画(する). It should behave as it did before.
Take out the "showmessage('警告!!');". It is no longer needed, and by not having a showmessage, we've made a program that can run unattended for long periods. Any messages will still be on show, but no one has had to click "承認する" to make a message box go away. You can also put "save this 警告 (or alarm) message to a data とじ込み/提出する" code into the 反応する... 手続きs... something not 供給するd for in a mere "showmessage".
Getting fancier....
It is possible that if you 延長する the program, there may be other 警告s (arising どこかよそで) that you wish to 現在の to the 使用者, so we are going to 修正する "ReactToWarning". Change the call to....
if scrollbar1.position>30 then ReactToWarning('Scrollbar Position');
(Don't try to run the program just yet.... you need also to...)
Change the 宣言 (Up at the 最高の,を越す, 近づく "私的な" to....
手続き ReactToWarning(sMsg:string);
... and make the 実施....
手続き TDD68f1.ReactToWarning(sMsg:string);
begin
scrollbar1.position:=0;
DD68fWarnings.memo1.lines.追加する('警告 seen at '+
DateTimeToStr(Now)+
' '+sMsg);
end;
Save. Run. Debug.
自白: That "scrollbar1.position:=0;" is a little kludgey. But not a big 取引,協定, so don't worry. It's just that it is too 明確な/細部. Code should 努力する/競う to be general, 柔軟な. If you change the 機械装置 by which a "警告" 条件 arises, and the "scrollbar1.position:=0;" may become irrelevant, but the fact may not be noticed, and that 半端物 little line of code may perplex you hours later when you つまずく across it and try to remember what it is doing there. It might have been better to put it where it was before, in the "if" 条項 in CheckAndHandleAlarmsOrWarnings.
(The "DateTimeToStr(Now)" item is all taken care of for you by Good Old Delphi/ Lazarus. It uses two built in 機能(する)/行事s, "Now" and "DateTimeToStr". The 判型 of the string will 変化させる from system to system, as it 答える/応じるs to how Windows has been configured on the system in question.)
This is the time to review the above; this is the "review it" point I 約束d earlier. Go 支援する, re-read what you've done. Be sure you are comfortable with what we've done so far before going on.
Happy? Good!
===
We have the 使用/適用 "doing things" nicely when there is a WARNING. (Scrollbar position over 30). Now we are going to make corresponding changes to the code to make ALARMS behave in a 類似の manner...
追加する DD68uAlarms to DD68u1's Uses 条項. (LD68uAlarms to LD68u1's Uses 条項.)
追加する...
手続き ReactToAlarm(sMsg:string);
... to the 宣言s. 追加する...
手続き TDD68f1.ReactToAlarm(sMsg:string);
begin
scrollbar1.position:=0;
DD68fAlarms.memo1.lines.追加する('Alarm seen at '+
DateTimeToStr(now)+
' '+sMsg);
end;
... just before the 部隊's final "end.", and rewrite...
手続き TDD68f1.CheckAndHandleAlarmsOrWarnings;
begin
if scrollbar1.position>60 then
ReactToAlarm('Scrollbar Position: '+inttostr(scrollbar1.position));
if scrollbar1.position>30 then
ReactToWarning(''Scrollbar Position: '+inttostr(scrollbar1.position)');
end;
Save. Run. Debug.
You may find that you get "extra" alarm or 警告 報告(する)/憶測s if you drag the scrollbar thumb tab into, say, the 警告 zone, and ぐずぐず残る with the mouse there. The extra 警告 comes if you 解放(する) the button too slowly.
You can give the 覚え書きs scrollbars, by the way. Use the 反対する 視察官.
===
I think it would be nice if the errors and 警告s were numbered, don't you?
In DD68u1, in the line after "{私的な 宣言s}", 追加する...
iNumWarnings,iNumAlarms:integer;
二塁打-click on DD68u1, to start a "爆撃する" FormCreate. 追加する to it, making it...
手続き TDD68f1.FormCreate(Sender: TObject); begin iNumWarnings:=0; iNumAlarms:=0; end;
Alter ReactToWarning, making it...
手続き TDD68f1.ReactToWarning(sMsg:string);
begin
scrollbar1.position:=0;
inc(iNumWarnings);
DD68fWarnings.memo1.lines.追加する(inttostr(iNumWarnings)+
': 警告 seen at '+
DateTimeToStr(now)+
' '+sMsg);
end;
.. and change ReactToAlarm the same way...
scrollbar1.position:=0;
inc(iNumAlarms);
DD68fAlarms.memo1.lines.追加する(inttostr(iNumAlarms)+
': Alarm seen at '+
DateTimeToStr(now)+
' '+sMsg);
=====
Next... something really tricky. 井戸/弁護士席, it seems so to me... but that's probably because I'm self taught. I wish I'd つまずくd on what follows a long time ago, as I think it is going to 証明する very, very powerful.
Given the level of this tutorial, I hope you are やめる comfortable passing parameters to subroutines? We've done a bit of it in this tutorial already. However, did you know that things like 覚え書きs can be passed to 手続きs? An example follows.
Instead of having....
DD68fAlarms.memo1.lines.追加する(inttostr(iNumAlarms)+
': Alarm seen at '+
DateTimeToStr(now)+
' '+sMsg);
and
DD68fWarnings.memo1.lines.追加する(inttostr(iNumWarnings)+
': 警告 seen at '+
DateTimeToStr(now)+
' '+sMsg);
in our program, we're going to create a WriteToMemo 手続き. It will still need all of the "stuff" that we had after the "lines.追加する(...", but it is still 価値(がある) having. You'll see. (I hope.)
In the 宣言s, 追加する....
手続き WriteToMemo(var meWhichMemo:TMemo;sMsg:string);
Just before the "end." at the 底(に届く) of DD68u1.pas, 追加する...
手続き TDD68f1.WriteToMemo(var meWhichMemo:TMemo;sMsg:string); begin meWhichMemo.lines.追加する(sMsg); end;
... and, just to make a start, to ReactToAlarm, just after the 存在するing "DD68fAlarms.memo1.....+sMsg);", 追加する...
WriteToMemo(DD68fAlarms.memo1,'hi');
The program should run. (If it doesn't, be sure you put the "var" in after "WriteToMemo(". Very important. It means that within the 手続き, you を取り引きする whatever 覚え書き you 言及/関連d... the actual 覚え書き... not a COPY of it, which would be the 事例/患者 さもなければ. (For example, we only made a copy of the "hi", which was passed as the second parameter.))
Once that's working, take out the "WriteToMemo...", 連合させる the two lines which 令状 things to the 覚え書き, make ReactToAlarm just....
scrollbar1.position:=0;
inc(iNumAlarms);
WriteToMemo(DD68fAlarms.memo1,
inttostr(iNumAlarms)+
': Alarm seen at '+
DateTimeToStr(now)+
' '+sMsg);
Make a 類似の change in ReactToWarning, to bring it in line with ReactToAlarm.
Presto! You've made the program more 前進するd. It still does the same things, but does them better. "Better" because the 詳細(に述べる)s of 令状ing to a 覚え書き... which you do at least twice... are all "wrapped up" in one 手続き. If you want to change how you 令状 things to 覚え書きs, you make the change in the 手続き. Thereafter, any 令状ing of 覚え書きs, 関わりなく what instance of that you are 関心d with, 作品 終始一貫して. If you'd left the 令状ing- to- 覚え書き at the mercy of the repeated fragments of code, you would almost certainly at some point 修正する one instance, but forget to 修正する one of the others.... and then wonder why your program didn't 成し遂げる 終始一貫して.
We won't take it very far here, but the に引き続いて illustrates an important technique.
Suppose you 手配中の,お尋ね者 to 記録,記録的な/記録する all the 警告s and alarms in two data とじ込み/提出するs. One for 警告s. One for alarms.
It isn't terribly hard, 現実に, but there are some 詳細(に述べる)s I can't 直面する going into here.
You'd have to 追加する code to 始める,決める things up to 令状 to the two data とじ込み/提出するs. Part of the "体制/機構" would mean that "writeln(dfWarnings(sMsg))" would 令状 what was in sMsg to the "警告s" datafile, and "writeln(dfAlarms(sMsg))" would 令状 what was in sMsg to the "Alarms" datafile.
**IF** you had everything 始める,決める up ahead of the first call to "WriteToMemo", then 追加するing just the に引き続いて two lines to WriteToMemo would 令状 lines to the two data とじ込み/提出するs...
if meWhichMemo=DD68fWarnings.memo1
then writeln(dfWarnings(sMsg));
if meWhichMemo=DD68fAlarms.memo1
then writeln(dfWarnings(sMsg));
STOP PRESS!.... I think there's an error in the above. I'm pretty sure that in the second satement, you want...
if meWhichMemo=DD68fAlarms.memo1
then writeln(dfAlarms(sMsg));
(The dfWarnings has been changed. Now dfAlarms is passed to writeln.)
"明白に"? (I would just change what the page says, but it has been a very long day. I 港/避難所't got the energy to 実験(する) this just now. Let me know which one is 権利, if you happen to go through this, 現実に try doing what it says? Or if you are sure, sure, sure? Thanks! "Stop 圧力(をかける)" ENDS
Simples!, isn't it, when you've seen the trick. You can pass a TMemo 反対する 正確に/まさに the way you pass things in varialbles! Who knew?!
(Another, いっそう少なく ふさわしい to these exact circumstances, approach is to just save the whole 覚え書き's contents from time to time. 作品 井戸/弁護士席 in other circumstances.)
It might be best to 改名する "WriteToMemo" something like "WriteToMemoAndDatafile" if the extra feature was 追加するd!
The clever thing to notice is that we are asking which 覚え書き the 手続き has been called to 令状 to. Doing something like "if c1=5 then..." is probably old hat to you, but when did you last build an "if" 声明 around a variable 持つ/拘留するing one of the 反対するs or 支配(する)/統制するs from your 使用/適用? (^_^)
It has taken us a while to build the WELL BUILT program we have... but it was 価値(がある) it, because it is so 平易な to 追加する things to a 井戸/弁護士席 built program.
I won't drag you though the 詳細(に述べる)s, but you could その上の "boil 負かす/撃墜する" what we have at this point, and 取って代わる ReactToWarning and ReactToAlarm with a 選び出す/独身 手続き, "反応する". It would have another parameter which would be passed when the 手続き was called. I'd use a byte type variable, because anything "smaller" saves very little, and using a byte-type variable leaves room for 未来 enhancements.
When calling "反応する", you would 始める,決める that extra parameter to 0 or 1, and inside "反応する" you would have some "if (it)=0 then... " and "if (it)=1 then..." 声明s, so that how the program 反応するs depends on whether it was an alarm or a 警告 that 誘発する/引き起こすd the need to 反応する.
Don't "worry" if anything from "Taking it その上の" wasn't (疑いを)晴らす... I only 始める,決める the ideas out very 概略で. しっかり掴むing that stuff isn't important. A useful (I hope!) extra, if you did しっかり掴む what I was trying to say.
I 約束d you that this program would also illustrate using Booleans to 支配(する)/統制する 外見s, even when the programmer can't tell the order things are going to happen in. Along the way, you're going to get another example of passing 支配(する)/統制するs to a subroutine.
The program's new 行為 will be as follows....
When an alarm or 警告 arises, the 関連した 覚え書き will flash attention-getting colors until a 使用者 clicks on a "警告 定評のある" or "Alarm 定評のある" button.
To 器具/実施する all of that will 要求する several modifications. You won't see the results until 近づく the end.
Before we move on to that, let me について言及する that if you 港/避難所't heard about 明言する/公表する diagrams as a way of planning a system, you might want to try my introduction to them. (Clicking on the link will open that in a new window, so you'll be able to 再開する this afterwards.) They are 効果的な in 打ち勝つing the shortcomings of flowcharts in an event driven 環境.
Going 支援する to our 現在の 事業/計画(する): Proceed by 追加するing "警告 定評のある" and "Alarm 定評のある" buttons to the main form. Call them buAckWarn and buAckAlarm.
Just after "iNumWarnings,iNumAlarms:integer;" in the 宣言s, 追加する....
boWarningAckd, boAlarmAckd:boolean;
.. and in the FormCreate handler, 始める,決める them both true.
boWarningAckd:=true; boAlarmAckd:=true;
At the 最高の,を越す of ReactToWarning, 追加する....
boWarningAckd:=誤った;
Yes: 誤った. (You have not yet 定評のある the 警告, have you?)
And 追加する 類似の to ReactToAlarm.
Make the handler for the buWarningAckd clicked event....
boWarningAckd:=true; MakeNormal(DD68fWarnings.memo1);
... and do 類似の for buAlarmAckd.
(It won't 収集する or run at this 行う/開催する/段階... you 港/避難所't told it how to do the MakeNormal 手続き. But apart from two (民事の)告訴s of ...
dd68u1.pas(61,13) Error: Identifier not 設立する "MakeNormal"
... it should almost run!
Just below the "end;" of CheckAndHandleAlarmsOrWarnings 追加する....
if boWarningAckd=誤った then Flash(DD68FWarnings.memo1,clBlue,clYellow); if boAlarmAckd=誤った then Flash(DD68FAlarms.memo1,clRed,clWindow);
... and it should all Just Work.... when you have 追加するd the 宣言s and 実施 code for Flash and MakeNormal. I'll leave you to take care of making the 宣言s. Here's the code for the 実施....
手続き TDD68f1.Flash(var meWhich:Tmemo;cl1,cl2:Tcolor);
begin
if meWhich.color=cl1 then begin
meWhich.color:=cl2;
meWhich.font.color:=cl1
end// no ; here
else begin
meWhich.color:=cl1;
meWhich.font.color:=cl2
end;//else
end;
手続き TDD68f1.MakeNormal(var meWhich:Tmemo);
begin
meWhich.font.color:=clBlack;
meWhich.color:=clWindow;//clWindow will make the background
//be whatever color the 使用者 has selected for window backgrounds
//across all of his/ her desktop.
end;
Whew! I'm exhausted. What about you? but... we're done... once you (疑いを)晴らす any bugs.
When a 警告 or alarm arises now, the corresponding 覚え書き will still get the new line, 記録,記録的な/記録するing when the event arose, but now, in 新規加入, the 覚え書き will flash colors, to draw attention to itself... until you 認める the 警告 or alarm by clicking the 関連した button.
A program you will need in 正確に/まさに this form? Of course not. A useful illustration of some 利益/興味ing/ useful programming techniques? I hope so!
|
|
Page 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org
....... P a g e . . . E n d s .....