Mnemorable

  • I love those who can smile in trouble, who can gather strength from distress, and grow brave by reflection. 'Tis the business of little minds to shrink, but they whose heart is firm, and whose conscience approves their conduct, will pursue their principles unto death. - [Leonardo da Vinci]
  • Standing on the Shoulder of Giants - One who develops future intellectual pursuits by understanding the research and works created by notable thinkers of the past.
  • A hundred times every day I remind myself that my inner and outer life are based on the labors of other men, living and dead, and that I must exert myself in order to give in the same measure as I have received and am still receiving... - [Albert Einstein]

Monday, October 27, 2008

充電電池

[Source]瘾科技-小薑雜談:充電電池

為了因應功能愈來愈強大的 3C 產品,電池技術也必須要不停地推陳出新,才能供應這一代愈來愈饑渴、愈來愈耗電的 3C 產品。最常見的四種充電電池 -- 鎳鎘、鎳氫、鋰離子和鋰聚合物到底有什麼不同?各有什麼優點和缺點?小薑在這篇裡嘗試著用網路上找得到的資料來分析給大家聽...

鎳鎘電池(NiCd)

是最古老的充電電池技術之一,早在 1899 年就被發明出來了。鎳鎘電池的優點是可以承受短時間的大量放電,而且充電過程是吸熱反應 -- 後者的特性讓它可以快速充電也不會對電池造成太大的損壞。鎳鎘電池的電壓是 1.2V,比一般鹼性電池標示的 1.5V 略少,但是因為鹼性電池放電的過程中電壓會持續下降,到沒電的時候通常只剩 1V,反而鎳鎘電池會一直很穩定的提供 1.2V 的電壓直到沒電為止,因此大部份使用鹼性電池的電子產品都可以放鎳鎘電池進去,沒有問題。

鎳鎘電池最著名的缺點,就是所謂的「記憶效應」,也就是當電池裡還有沒用完的電,就再充電時,電池就會「記得」這個位置,以後電用到剩這麼多時,電池就會發生和沒電一樣的反應(電壓瞬間降低)。所以鎳鎘充電前必須要經過一段放電的過程,將電力放乾之後才能再充電。大部份鎳鎘電池的充電器都會有自動放電的功能。

鎳鎘電池因為蓄電量比較小(大概只有鹼性電池的 1/4),而且鎘是有毒重金屬,所以最近比較少看到了。大部份應用中它都已經被相近的鎳氫電池(NiMH)所取代。

鎳氫電池(NiMH)

鎳氫電池和鎳鎘電池是差不多的技術,只是將陽極從鎘換成了氫化物而已。它大部份的特性和鎳鎘電池一樣,只是蓄電量更高、記憶效應也比較不那麼明顯(但其實還是存在)。鎳氫電池最大的問題,是它有很高的自放電率,也就是明明是充飽電的電池,放在一邊不用一個月,電力可以少掉 30% 之譜。

在使用三號(AA)和四號(AAA)規格電池的應用中,鎳氫充電電池目前是主流,但對蓄電量有更高的須求,或是需要將體積做得更小時,就要靠鋰離子電池了...

鋰離子電池(Li-ion)

鋰離子電池幾乎是夢幻的電池,蓄電量高、體積小、重量輕、沒有記憶效應、電壓高、而且自放電小,也就無怪乎現代大部份見得到的 3C 產品都是使用鋰離子(或鋰聚合物)電池了。

但看似完美的鋰離子電池還是有危險存在的 -- 最明顯的莫過於它有蠻高的自爆傾向,而將這麼多能量擠在這麼小的空間裡,自爆起來很壯觀就在意料之中了。為了避免危險的發生,鋰電池必須要加入很多保護的措施,在電池充過頭或有過熱的跡象時自動斷電。這些額外的電路和機構,是為什麼沒有三號/四號大小的鋰離子電池,以及為什麼筆電電池價格如此高昂的原因。

鋰離子電池還有一個比較不為人知的有趣特性,就是不管你有沒有在用它,它的最大蓄電量都會隨著電池材料的氧化而逐漸降低。以一般常溫來說,鋰離子電池的蓄電力大約每年會下降 20% 左右,而且溫度愈高、充得愈飽,下降得愈快。所以如果你的筆電散熱比較差的話,長時間以滿電力處在 60°c 環境下的鋰電池可以在三個月內減掉 40% 的蓄電力。

下面是保養鋰電池的建議:

  • 不要把電用到光才充電 - 鋰電池不喜歡被放電放到完,所以如果你常發現自已把筆電的電力用到乾的話,那就換顆大一點的電池吧!
  • 不要把電充到全滿 - 前面說過,電池充得愈飽,蓄電力下降得愈快,所以保持 60~80% 飽是最佳的狀態。可惜好像除了 Panasonic 的筆電外,要達到這樣並不容易。
  • 每三十輪普通的充放電,就要來一次「用到乾」放電 - 鋰離子電池本身不怕短時間、小量的充放電,但先前提過的保護回路可能會因此而誤判到底現在電池裡有多少電量。一次大放電把電用乾,再充到全飽應該就能將保護回路「校正」回來。很多筆電都有軟體或甚至在 BIOS 裡提供這樣的功能。
  • 筆電用 AC 電源時,把電池拔下來 - 這也是因為先前說的蓄電力下降問題。把電池拔下來,至少可以讓它不用接觸到電腦本身的高溫。如果再把電池丟到冰箱裡,效果更好...
  • 電池收起來時,留約 40% 的電在裡面 - 留太多會蓄電量降低的問題,留太少電池會損壞。真是難伺候啊!
  • 買電池一定要買新的 - 新的電池才有滿的電量喔!
鋰聚合物電池(Li-Pol)

鋰聚合物電池和鋰離子電池的原理一樣,只是電解質的部份用聚合物來取代。這讓鋰聚合電池可以做成各式各樣的形狀(對消費者來說可不是好事 = =),符合不同的須求。鋰聚合物電池也比較安全,比鋰離子電池要耐高溫、撞擊,但在過充時仍然有爆炸的危險。其他的保養原則都和鋰離子電池一樣(所以用鋰電池的手機寧可天天充電,也不要用光電了才充)。

Wednesday, October 15, 2008

How to use TClientDataset as memory dataset

As you know starting from Delphi 3, Borland included TClientDataset component as a database-independent engine.

Generally this component is used for multi-tier environments when you transfer from server application to client application your data (using TProvider).

But today I want to show how to use standard TClientDataset component for memory-dataset without any multi-tiered application.

On any archive you may find some third-party memory datasets:
- TRxMemoryData from freeware RxLib/JVCL (I must say that only TMemoryTable from RX depends from BDE. TRxMemoryData don't use BDE)
- DevExpress MemData
- KbmMemTable
and a lot of another components

Also some from you use third-party database engines (Apollo/DBISAM/Halcyon/...) in mode when you don't need a real database. Exists a lot of task when real database is not required. All what you need is some temporary dataset.

So I want to show how to use TClientDataset in such mode on small sample.
1. you must create a TClientDataset instance. You may do it in design-time (simply drop a component on form) or in run-time (for example, in OnCreate event of your form):
table := TClientDataset.Create(Application);

2. you must add the field defintions:

table.FieldDefs.Add('ID', ftInteger, 0, False);
table.FieldDefs.Add('Status', ftString, 10, False);
table.FieldDefs.Add('Created', ftDate, 0, False);
table.FieldDefs.Add('Volume', ftFloat, 0, False);

3. create a dataset with specified structure:

table.CreateDataset

4. open a dataset:

table.Open

5. it's all! Now you may add/edit/delete records, change an order (sort) and any another action that is available for any dataset.

For example, to add random values to records:

for i := 1 to 100 do
begin
table.Append;
table.FieldByName('ID').AsInteger := i;
table.FieldByName('Status').AsString := 'Code'+IntToStr(i);
table.FieldByName('Created').AsDateTime := Date();
table.FieldByName('Volume').AsFloat := Random(10000);
table.Post;
end;

6. if you want to change an order for records, simply change IndexFieldNames property. For example, next command will sort your memory dataset by Created field:

table.IndexFieldNames := 'Created';

7. note that TClientDataset also allow to save memory dataset to file and load from file:

table.SaveToFile('c:\mem.cds');
table.LoadFromFile('c:\mem.cds');

A few file formats are supported - internal cds-format and xml-format

Of course, you may use SMImport suite for save/load too - it will work with such memory dataset without any problems. So you may expand your application and load data from MS Excel-spreadsheet or MS Access database, for example.

So in such manner you may transfer your data between applications/computers, update record etc

As example, you may use xml-file instead ini-file and store there any number of items without limitations on size/value types etc. Just load it to TClientDataset and navigate thru stored options as thru dataset.

PS: of course, you may also display such memory dataset in DBGrid or print it using any report engine. Also you may export it in any file format using SMExport (http://www.scalabium.com/sme)


TJvMemoryData : 不支持 Filter
TClientDataset : 不支持 LoadFromData

Tuesday, October 14, 2008

Getting an IP Address from a domain name

[Source]

procedure TForm1.Button1Click(Sender: TObject);
begin
WSocket1.OnDnsLookupDone := WSocket1DnsLookupDone;
WSocket1.DnsLookup('www.skpontiac.com');
end;

procedure TForm1.WSocket1DnsLookupDone(Sender: TObject; ErrCode: Word);
begin
if ErrCode = 0 then
Memo1.Lines.AddStrings(WSocket1.DnsResultList)
else
Memo1.Lines.Add(WSocket.WSocketErrorDesc(ErrCode))
end;

The ICS (Internet Component Suite, freeware) is available on the partner CD
or downloadable here
http://www.overbyte.be.