このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Every Lazarus (or Delphi) program should have HOME - - - - - Lazarus Tutorials TOC - - - - - - Other 構成要素 for programmers

Lazarus/ Delphi Tips and Tricks

Things every program should have

とじ込み/提出する: lt1Ne.htm

Most of this is just things I like to see in any program. I don't think any are 要求するd by Lazarus... but many of them are things you せねばならない do somehow, just as a 事柄 of Good programming Practice.... in my opinion. That opinion has been honed by many years of 支払う/賃金ing the price of not doing some good programming practices.

This page is a minor one in the general universe of my tutorials on programming; it is not a typical page.

代案/選択肢 source

The page you are reading now is good for a discussion of some of my "should be in every app's code" ideas.

If you just want to take advantage of my ideas, go to my July 2022 page which is おもに about something else, but which has a "boilerplate" 事業/計画(する) with the my "should be in"s in it. You can download a .zip with all of the parts of the 事業/計画(する) in it. Fetch. Unzip. Click the .lpi とじ込み/提出する.

(You will be able to "(土地などの)細長い一片 out" the other stuff in that 事業/計画(する) easily.)

Not only is everything in place for you... 含むing a simple (but extendable) ini とじ込み/提出する system, but the code is Just That Little Bit Better, because I wrote it several years after I wrote the page you are reading.

So... to learn: This page. To use: The page the link above takes you to.

指名するing Of Parts

I've been 令状ing programs for a long time. I.e. producing code to make an app. In what follows, where you see "app", or "使用/適用", I mean what you may call "a program". When I 言及する to "code", I am speaking of the stuff that makes computers do things. (Not what the 秘かに調査するs... and personal-privacy-aware modern people... use!)

Give the app a PRODUCT CODE

All of my apps have a short "指名する", or "model number", "製品 code". For instance, I have a number of apps which Teach MAthematics. Their 指名するs are things like TMA005, TMA025.

Having a "code" for each app makes 記録,記録的な/記録する keeping so much easier and 強健な. There are also times when 存在 able to say "that one" very concisely is useful.

Mainstream programs also get more human friendly 指名するs... for instance, TMA036 is also known as "Goldie's Game", because it was 奮起させるd by a teacher at Radleigh School, England. The .exe is called TMA036.exe, but there is nothing to stop 使用者s from setting up a shortcut which 申し込む/申し出s "Goldie's Game- TMA036".

公式文書,認める, by the way the padding of numbers to maybe two, better three digits by 主要な 無s. If you do this, the folders for your work will appear in 数値/数字による order in directory listings.

Once the app has a 製品 code, you can make the "button" on a Windows taskbar give the 製品 code with, in the FormCreate event handler with....

  使用/適用.肩書を与える:='LT999';

跡をつける the VERSION

Call it what you like, but somewhere, somehow, put into your code an 指示,表示する物 of what 見解/翻訳/版 the copy you are looking at is. And make that 明白な to 使用者s of your code.

My approach...

I put a constant which I always call "vers" in 近づく the 最高の,を越す of the code. Constants are a little funny... you DO put the 半分-結腸 at the end of the line, but the thing that is very like an assignment is done with just and equals 調印する, not an ":="

  const vers='26 Jan 16';

I 簡単に use the 現在の date for a 見解/翻訳/版 ID. If I need to 公式文書,認める a second 見解/翻訳/版 on a given day, I 追加する "b" the first time, "c" after that, etc. I never use "a", to 避ける having both a "26Jan16" AND a "26Jan16a", and thus creating a chance for 混乱.

Once you have 設立するd "vers", I 一般に, in the FormCreate handler, do something like....

  LT999f1.caption:='LT999- デモ of Lazarus Prgmming. Vers '+ vers;

.. which will put the text, and the app's 現在の 見解/翻訳/版 in the 肩書を与える 妨げる/法廷,弁護士業 of the app's window. (You will need to change the LT999f1 you see above to the 指名する of your 使用/適用's main form.)

You don't need to update the 見解/翻訳/版 ID every time you make the slightest change to the code.... but if you have saved a backup copy, or saved a copy on a second 貯蔵 装置, or printed hardcopy, and you change the code, change the 見解/翻訳/版 ID. In other words, 保護する yourself from even a remote 可能性 of having two copies of the code, or an .exe とじ込み/提出する, in 前線 of you which are different, but which do not have, built in, something to tell you which of them is the newer.

関係のある to "見解/翻訳/版"

It is difficult to have too many rems (発言/述べるs, comments) in your code. I keep a rough スピードを出す/記録につける of the app's 開発 at the 長,率いる of the code. Just a bunch of rems 記録,記録的な/記録するing problems 遭遇(する)d, and when they were solved. Ditto, in the same 一連の comments, features 追加するd.

Just under the line defining the vers constant, I like to 手早く書き留める a short 公式文書,認める about when I started 令状ing the app, 含むing what was going on in my life that day. It is amusing, from time to time when revisiting the code, to see how long it has been around, what I was doing 支援する then.

Use 範囲 Checking

"範囲 checking" is a 道具 that is turned off by default. If you have an app where 死刑執行 速度(を上げる) is a problem, you may get some 速度(を上げる) 伸び(る)s by turning 範囲 checking off again, after you've built the app... but while you are working on it, I would recommend turning 範囲 checking on. There is a compiler 指示的な {$R} which is DIFFERENT from the 範囲 checking 支配(する)/統制するs, {$R+} and {$R-}.

{$R} can't appear on it's own. If a + or - follow, you turn 範囲 checking on or off. さもなければ, $R should be followed by something like the 基準 *.lfm, which tells the compiler where to find something. (I've never had need of messing with this, and so am not fully 知らせるd as to what $R *.lfm 始める,決めるs!)

Because of the 可能性のある for 混乱, I usually put my $R+ just after the $R *.lfm that appears "automatically" when you start a new app....

  実施
  {$R *.lfm}
  {$R+}

A LINK to your website

There fancier ways to send people to your website, but the に引き続いて is a simple way to send people there....

Put a button on your page 説 "Click here to copy http://sheepdogsoftware.co.uk to your clipboard".

Put the に引き続いて in the Click event handler...

  Clipboard.(疑いを)晴らす;
  Clipboard.AsText:='https://sheepdogguides.com/lut/lt3Ng-1.htm';

... and, so that it will work, put "Clipbrd" in the app's uses 条項.

(My thanks to http://wiki.lazarus.freepascal.org/Clipboard for showing me how to do that!)

What HAS FOCUS at start?

I often put a "やめる" button on my apps. And, when I've not been careful, the app 開始する,打ち上げるs with that button having the 焦点(を合わせる). In which 事例/患者, if the 使用者 圧力(をかける)s the "Enter" 重要な, the app の近くにs.

Now... hopefully, we never 攻撃する,衝突する the enter 重要な without knowing what we are doing. But いつかs Mr. Murphy "helps".

I like to make sure that something 比較して 害のない has the 焦点(を合わせる) when the app 開始する,打ち上げるs.

If you don't do anything else, the tab order will 決定する what has 焦点(を合わせる). (And setting up a good tab order is a good idea.)

To make sure that, say, the button called buAddComment has 焦点(を合わせる) when the app 開始する,打ち上げるs, here is what you do....

Put...

  buAddCommment.setfocus;

... to your code.

平易な, you say! And it is. Just don't put it in the "obvious" place, the FormCreate event handler. That will not work... you are trying to give the 焦点(を合わせる) to something which doesn't, as far as Windows is 関心d, may not yet 存在する. The form... and the buttons on it... are still 存在 created during the FormCreate handler. Ah! Gotcha!

However, there is another event, FormActivate, which is a good place to put the setfocus 命令(する). The button won't be given 焦点(を合わせる) every time you maximize, 回復する, etc, the form. It won't be given 焦点(を合わせる) if you have gone off to a different app, and then come 支援する. But the button will have 焦点(を合わせる) when the app 開始する,打ち上げるs.

(The tab order 所有物/資産/財産 of your 支配(する)/統制するs is, by the way, Good For You, too. And let's say you have five things 割り当てるd numbers so that tabbing will cycle through them. If you 始める,決める the "enabled" 所有物/資産/財産 of one of them to 誤った, it doesn't faze the tabbing 過程. The computer just skips over any 無能にするd 支配(する)/統制するs which it would さもなければ visit.)

Something a little harder- INI FILES

So far, my suggestions have been 平易な to 器具/実施する.

Not so 平易な, and something more open to 審議, is the idea of giving every program an "ini" とじ込み/提出する. (I believe Linux 使用者s would call it a "config" とじ込み/提出する.)

Now-a-days, in Windows, at least, we are "encouraged" to use the registry. 罰金... if you really need it. I am too humble to want to mess with something so central to the smooth running of my 顧客's PCs. My apps are not so grand as to need to use the registry.

The downside, and I think it a minor one, is that you have to have 許可 to 令状 to the disk of whatever system the app is running on.

その上に, I like to put the ini とじ込み/提出する in the same folder as the app... another 決定/判定勝ち(する) with its プロの/賛成のs and 反対/詐欺s.

But, please: At least consider using an ini とじ込み/提出する, if only to "remember" the position and sizing of the window when the 使用者 was done with your app.

How To Do Ini とじ込み/提出するs is discussed in greater depth in the tutorial the link will take you to, however...

Here's a very あらましの 指示,表示する物 of some of the basics...

Put "IniFiles" in the 使用/適用's "Uses" 条項.

始める,決める up a 全世界の variable, sIniFileName.

手続き TLDN006f1.FormCreate(Sender: TObject);
var wHour, wMin, wSec, wMilli : Word;//Needed for DecodeTime
    dfIniFile:TIniFile;//"df" in 指名する from "datafile". Could be anything.
begin
  sIniFileName:='LT999ini.txt';
  DecodeTime(now, wHour, wMin, wSec,wMilli);//Built into Lazarus and Delphi
      //"now" is a built in 機能(する)/行事 to 選ぶ up the 現在の time from your system.
  bThisOpening:=wMin;
  laThisOpening.caption:=inttostr(bThisOpening);

  //Heart of reading from ini とじ込み/提出する
  dfIniFile:=TIniFile.Create(sIniFileName);

  with dfIniFile do begin
     bPrevOpening:=ReadInteger('以前','Opened At',255);
     end;//with...

  dfIniFile.解放する/自由な;
//End of "Heart of...."

//Now use what you read....
  if bPrevOpening=255
    then laPrevOpening.caption:='No 記録,記録的な/記録する of previous 開始'//no ; here
    else laPrevOpening.caption:=IntToStr(bPrevOpening);

end;//FormCreate

... and, to save- to- ini- とじ込み/提出する what was in 使用/適用 when it の近くにs....

手続き TLDN006f1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var dfIniFile:TInifile;
begin
 dfIniFile:=TIniFile.Create(sIniFileName);
 with dfIniFile do begin

  WriteInteger('以前','Opened At',bPrevOpening);

  end;//with...
 dfIniFile.解放する/自由な;

end;//Of FormClose

I hope the above has useful bits!





Search across all my 場所/位置s with the Google search...

Custom Search
            力/強力にするd by FreeFind
  場所/位置 search Web search
場所/位置 地図/計画する    What's New    Search This search 単に looks for the words you enter. It won't answer "Where can I download InpOut32?"
広告 from page's editor: Yes.. I do enjoy 収集するing these things for you. I hope they are helpful. However... this doesn't 支払う/賃金 my 法案s!!! Sheepdog ソフトウェア (tm) is supposed to help do that, so if you 設立する this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.

Link to Lazarus Tutorials main page
How to 接触する the editor of this page, Tom Boyd



Valid HTML 4.01 Transitional Page 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes. There were two "unknown せいにするs" in Google+ button code. Sigh.


If this page 原因(となる)s a script to run, why? Because of things like Google パネル盤s, and the code for the search button. Why do I について言及する scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....