Changeset 24 for branches/lazarus/UCore.pas
- Timestamp:
- Sep 8, 2010, 4:17:21 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/lazarus/UCore.pas
r23 r24 6 6 7 7 uses 8 USqlDatabase ;8 USqlDatabase, Classes, SysUtils, StrUtils; 9 9 10 10 type … … 12 12 TPageProducer = function: string; 13 13 14 function MakeLink(Text, URL: string): string; 15 function NavigationMakeLink(Module, Page: string): string; 14 16 function InsertIcon(FileName: string): string; 17 function IconedLink(Link, Text: string): string; 15 18 function HtmlLink(Text, Target: string): string; 16 19 function ShowHeader(Title, Path: string): string; … … 18 21 function Explode(Separator: Char; Data: string): TArrayOfString; 19 22 function HumanDate(Date: string): string; 20 procedure RegisterPage(Name: string; Producer: TPageProducer);21 23 function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer): string; 22 24 function StrRepeat(Data: string; Count: Integer): string; 23 24 type25 TRegistredPage = record26 Name: string;27 Producer: TPageProducer;28 end;29 30 var31 Pages: array of TRegistredPage;32 Database: TSqlDatabase;33 25 34 26 implementation 35 27 36 28 uses 37 SysUtils, UConfig; 38 39 procedure RegisterPage(Name: string; Producer: TPageProducer); 40 begin 41 SetLength(Pages, Length(Pages) + 1); 42 Pages[High(Pages)].Name := Name; 43 Pages[High(Pages)].Producer := Producer; 44 end; 29 UConfig; 45 30 46 31 function HtmlLink(Text, Target: string): string; … … 110 95 end; 111 96 112 procedure Init; 113 var 114 DbRows: TDbRows; 97 function LastPos(const SubStr: String; const S: String): Integer; 115 98 begin 116 Database := TSqlDatabase.Create; 117 with Database do begin 118 Hostname := DatabaseHostName; 119 Database := DatabaseDatabase; 120 UserName := DatabaseUserName; 121 Password := DatabasePassword; 122 Connect; 123 end; 124 DbRows := Database.Query('SET NAMES utf8'); 125 DbRows.Free; 99 Result := Pos(ReverseString(SubStr), ReverseString(S)); 100 101 if (Result <> 0) then 102 Result := ((Length(S) - Length(SubStr)) + 1) - Result + 1; 126 103 end; 127 104 128 procedure Done; 105 function IconedLink(Link, Text: string): string; 106 var 107 Extension: string; 108 Icon: string; 129 109 begin 130 Database.Free; 110 Extension := Copy(Link, LastPos(Link, '.') + 1, Length(Link)); 111 Icon := '<img src="images/icons/' + Extension + '.gif" alt="' + Extension + '"> '; 112 Result := Icon + '<a href="' + Link + '">' + Text + '</a>'; 113 end; 114 115 function MakeLink(Text, URL: string): string; 116 begin 117 Result := '<a href="' + URL + '">' + Text + '</a>'; 118 end; 119 120 function NavigationMakeLink(Module, Page: string): string; 121 begin 122 Result := '?m=' + Module + '&p=' + Page; 131 123 end; 132 124 … … 179 171 initialization 180 172 181 Init;182 183 173 finalization 184 174 185 Done;186 175 end.
Note:
See TracChangeset
for help on using the changeset viewer.