Extended Format Function/pl
Opis
Moduł efmtf to zestaw klas i procedur umożliwiający formatowanie ciągów tekstowych na podstawie parametrów przekazanych w tablicy, z możliwością dodawania własnych reguł formatowania dla zmiennych obiektowych oraz wsparciem dla języka SQL. Moduł jest nadal zależny od standardowych funkcji FormatDateTime oraz Format.
Przykłady
Formatowanie z adresowaniem zmiennych
S := Fmt('string: {0:s}, integer: {1:d}, money: {2:m}, float: {2:f}', ['test', 1, 22.3]);
wynik: string: test, integer: 1, money: 22.30 z??, float: 22.3Adresowanie mieszane i domyślne formatowanie
S := Fmt('string: {}, integer: {}, money: {:m}, float: {2}', ['test', 1, 22.3]);
wynik: string: test, integer: 1, money: 22.30 z??, float: 22.3Wsparcie dla SQL (parametry pisane z dużej litery):
S := Fmt('SELECT * FROM employees WHERE FirstName = {:S} AND DateHired < {:TD};', ['John', Now]);
wynik: SELECT * FROM employees WHERE FirstName = 'John' AND DateHired < '2009-01-01';Wsparcie dla parametrów globalnych
SetParam('test', 'World');
S := Fmt('Hello {$test}!');
wynik: Hello World!Wsparcie dla formatowania zmiennych obiektowych:
// funkcja formatująca
function FormFmt(AObject: TObject; Mode: Char; Param: string): string;
var
f: TForm;
begin
if AObject is TForm then
begin
f := TForm(AObject);
if Param = 'caption' then
Result := f.Caption
else
Result := f.Name;
end;
end;
// przykład
RegisterFunction(TForm, FormFmt);
S := Fmt('caption: {0:scaption}, name: {0:s}', [Form1]);Escaped String
S := Fmt('\{2 + 2\} * 2, {:SE}', ['Hello'#13#10'World!']);
wynik: {2 + 2} * 2, 'Hello\r\nWorld!'Download
- Wersja: 1 RC 1
- Źródło: http://rapidshare.com/files/178670102/efmtf.zip
Licencja
- LGPL 2 lub nowsza
Zmiany
- 2009-01-01 (1 RC 1): Wersja początkowa
Autor
- Maciej Kaczkowski - maciejkaczkowski@gmail.com
From the Free Pascal wiki, page "Extended Format Function/pl", as it stood on 2020-02-14 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
