E2202 Required package ‘vcl’ not found

1. Error: tmsdXXXX.dpk(165) Fatal: E2202 Required package ‘vcl’ not found OR tmsdXXXX.dpk(165) Fatal: E2202 Required package ‘rtl’ not found

This means that your Delphi library path is not properly setup. Please make sure that the folder is included in your library path where vcl.dcp is located, this normally is $(BDS)\lib  继续阅读

Delphi编程注意事项—摘录收藏

 

  • 如果需要传递对象参数则放在函数参数里,这样就由调用者来创建和释放对象。
    例:[允许] function SomeOne(list:PStrList):boolean;
    当然,NewXXX之类的创建对象的函数除外。一直存在的全局对象也除外,这些全局对象将在初始化时创建,结束时释放。
    类定义中如果重载了Destory必须在里面加上inherited,否则不会释放的。
  • 使用对象(object)还是记录结构(record)。
    在有关性能方面的服务程序中:
    只产生单个实例或少于10个实例则允许使用对象。
    否则一律使用记录结构。
    在GUI方面都使用对象,但是不得超过五级继承。
    纯数据信息必须使用记录结构。
  • 错误、异常处理规则:
    1.Test,Check,Is开头的函数并不抛出异常,只检验。
    2.其他函数遇到错误或异常都要抛出异常,使用raise显式抛出,
    并且在函数文档中注明抛出异常的种类,方便使用者处理。
    3.如果需要屏蔽异常,则显式地写 try..except语句拦截。
  • 创建和释放
    在什么情况下使用free,什么情况下使用freeandnil。
    1.free之后不再使用的函数局部变量要使用free。
    2. 全局变量或者Free后继续使用的变量要使用FreeAndNil;

【摘自】Delphi编程注意事项—转贴收藏 – henreash的专栏 – CSDN博客

Delphi tip#50: to execute a program and wait a result

How can I execute a program and have my code wait until it is finished?

The next procedure allows you to execute a program and to wait until it’s finished:

function WinExecAndWait32(FileName: string; Visibility: Integer): dWord;
var
  zAppName: array[0..512] of Char;
  zCurDir: array[0..255] of Char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, Sizeof(StartupInfo), #0);
  StartupInfo.cb := Sizeof(StartupInfo);

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
           zAppName, { pointer to command line string }
           nil, { pointer to process security attributes }
           nil, { pointer to thread security attributes }
           false, { handle inheritance flag }
           CREATE_NEW_CONSOLE or { creation flags }
           NORMAL_PRIORITY_CLASS,
           nil, { pointer to new environment block }
           nil, { pointer to current directory name }
           StartupInfo, { pointer to STARTUPINFO }
           ProcessInfo) then
    Result := -1 { pointer to PROCESS_INF }
  else
  begin
    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end;

Delphi tip#50: to execute a program and wait a result

Delphi tip#48: CRC32 calculation

 

Algorithm of CRC32 calculation for file

If you need calculate a CRC32 for some file or some string, then you must do:
1. build a CRC table
2. calculate a CRC for each line of your file
3. calculate a total CRC
1. CRC table creation:

type
  Long = record
    LoWord: Word;
    HiWord: Word;
  end;

const
  CRCPOLY = $EDB88320;

var
  CRCTable: array[0..512] Of Longint;

procedure BuildCRCTable;
var
  i, j: Word;
  r: Longint;
begin
  FillChar(CRCTable, SizeOf(CRCTable), 0);
  for i := 0 to 255 do
  begin
    r := i shl 1;
    for j := 8 downto 0 do
      if (r and 1) <> 0 then
        r := (r Shr 1) xor CRCPOLY
      else
        r := r shr 1;
    CRCTable[i] := r;
   end;
end;

继续阅读

the network is available or not

判断电脑是否联网:

#41:PC is connected to a network or not

If you want to know if the PC is connected to a network under MS Windows then you can call a GetSystemMetrics() function (Windows API) with SM_NETWORK parameter:

if (GetSystemMetrics(SM_NETWORK) AND $01 = $01) then
    <PC is attached to network>
else
    <PC is not attached to network>

Best delphi site–来自board4all的整理,推荐

原帖见:Best delphi site? – Board4All

http://www.board4all.cz/

主要是各种控件下载,破解版,源码等,rs,hotfile下载,寻找最新破解组件的最佳去处。推荐

http://delphi.about.com/

主要讨论编程技巧,方法,有不少的技巧集合,综合等,也是学习Delphi的好地方。推荐

components

http://www.torry.net/ 组件,历史悠久了。

http://www.sourcecodeonline.com/sources/delphi.html

组件和控件列表,集中了不少开源和不开源的组件

http://www.koders.com/zeitgeist/delphi/

多种语言的控件,主要是可以看到源码

http://stackoverflow.com/questions/tagged/delphi

stackoverflow.com不用多介绍了吧,问答型的

http://delphibasics.co.uk/

delphi语言基础,类型,过程,语法等,例子很详细,推荐

http://www.scalabium.com/index.html

提供一个smcomponents免费控件,还有smimport和smexport等收费控件,好像都是数据库相关的多。

另外,有个Delphi的faq和tips,都很不错的,可以看看。

http://www.delphidabbler.com/tips

不只有tips,还提供了一个codesnips,就是代码片段管理器,另外,还有不少的有用,开源的控件和单元。

推荐

 

http://www.delphi3000.com

历史悠久了。

http://www.delphiforfun.org    (the best in algorithms)

算法相关的比较多,可以找到经典的大整数等的实现例子,还有相应源码。推荐

http://www.gtdelphicomponents.gr

几个Delphi控件和程序

Self-Delete程序存疑

标  题: Self-Delete程序之Delphi版本,终于搞定了。
发信站: BBS 水木清华站 (Mon Jun  4 20:50:42 2001)
到Borland的论坛去问了问,确实跟laoduan说得一样,要自己GetProcAddress。代码如下:

program Project1;

{$APPTYPE CONSOLE}
uses
  SysUtils,
  Windows;

procedure DeleteSelf;
var
  hModule: THandle;
  buff: array[0..255] of Char;
  hKernel32: THandle;
  pExitProcess, pDeleteFileA, pUnmapViewOfFile: Pointer;
begin
  hModule := GetModuleHandle(nil);
  GetModuleFileName(hModule, buff, sizeof(buff));
  CloseHandle(THandle(4));
  hKernel32 := GetModuleHandle('KERNEL32');
  pExitProcess := GetProcAddress(hKernel32, 'ExitProcess');
  pDeleteFileA := GetProcAddress(hKernel32, 'DeleteFileA');
  pUnmapViewOfFile := GetProcAddress(hKernel32, 'UnmapViewOfFile');
  asm
         LEA         EAX, buff
         PUSH        0
         PUSH        0
         PUSH        EAX
         PUSH        pExitProcess
         PUSH        hModule
         PUSH        pDeleteFileA
         PUSH        pUnmapViewOfFile
         RET
  end;
end;

begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
    DeleteSelf;
  except
    on E: Exception do
    begin
       Writeln(E.Classname, ': ', E.Message);
    end;
  end;
end.

现在有一点比较古怪,那就是必须把代码放在一个Procedure里,

继续阅读

Delphi 中创建无dos窗口console程序

要创建一个console的控制台程序,即无窗体的程序,但是,Delphi默认的console application类型的project,运行的时候,会有一个黑黑的dos窗口。如图:

image

要让程序不显示dos窗口,而在后台运行,方法,就是注释掉“{$APPTYPE CONSOLE}”的程序类型。这样,产生的程序就直接在后台运行,没有dos窗体。

继续阅读

SQLite Wrapper for Delphi

 

  • Aducom’s SQLite: Open source (NewBSD) Delphi (4..2007) C++ (BCB5, 6, 2007) and 2009/2010 components for SQLite V2.8.x and V3.x.x. (like TASQLiteDB, TASQLiteQuery, TASQLiteTable, TASQLiteUpdateSQL and others). No need for the BDE but Delphi standard edition is not supported. Support for static linking (no dll needed), utf-8, utf-16 and unidirectonal dataset. (updated 1 dec 2009)
  • RemObjects AnyDAC: High-speed, universal data access engine for SQLite, Firebird, MySQL, MS SQL Server, Oracle, PostgreSQL, Interbase, MS Access, IBM DB2, Sybase ASA, DbExpress, ODBC, that simplifies the task of building CodeGear Delphi, C++Builder and Free Pascal Compiler database applications. (commercial)
  • Devart Universal Data Access Components (UniDAC) – a library of nonvisual cross-database data access components for Delphi, Delphi for .NET, C++Builder, and FreePascal. The list of supported databases includes Oracle, Microsoft SQL Server, MySQL, InterBase, Firebird, PostgreSQL, and SQLite.
  • ZeosLIB: The ZeosLib is a set of database components for MySQL, PostgreSQL, Interbase, Firebird, MS SQL, Sybase, Oracle, DB/2, SQLite (2.8.x & 3.x – in cvs) for Delphi, Kylix, C++ Builder, Lazarus
  • DISQLite3: The fully embedded, no-DLL SQLite3 solution for Delphi (D4, D5, D6, D7, D2005, D2006, D2007, D2009) including FTS1, FTS2, FTS3, R-Tree, and encryption. DISQLite3 compiles with Delphi standard / personal and does NOT require sqlite3.dll. It provides the complete SQLite3 API, is regularly updated, very small, well documented, tightly integrated, and carefully optimized. As a result, DISQLite3 outperforms sqlite3.dll up to 50% for common operations. Free personal edition.
  • Fast and lean wrappers, browser, date/time and soundEx functions http://www.it77.de/sqlite/sqlite.htm ("Last update 28.05.2004")
  • Simple SQLite 3.0 wrapper, no TDataset or databinding, but fast and easy to use. Free for any purpose. Uses external sqlite3.dll for easy updating. Supports Delphi 2009. http://www.itwriting.com/blog/?page_id=659. Last Update 16 October 2008.
  • Delphi class for SQLite. http://www.torry.net/db/direct/db_directsql/tsqlite.zip (As of 30 April 2007, ‘Error 404. Missing File.’)
  • LibSQL – Delphi/Kylix/Freepascal interface for SQLite, MySQL and ODBC32. http://sourceforge.net/projects/libsql
  • Dataset descendant for SQLite: http://sourceforge.net/projects/sqlite4delphi (** dead project **)
  • SQLitePass library : SQLite Pass is a simple set of components designed for Lazarus-fpc and Delphi, to give access to SQLite databases. This project is open source, released under LGPL license. Those libraries and components are free.SQLite Download : http://source.online.free.fr
  • SqliteWrap Simple Sqlite3 wrapper based on work of Tim Anderson. It have cleaned code and some additional features. http://www.ararat.cz/doku.php/en:sqlitewrap
  • ___________________

    [From] SQLite Wiki