source: trunk/Packages/CoolWeb/Common/UHtmlClasses.pas

Last change on this file was 5, checked in by chronos, 12 years ago
  • Added: Required packages.
File size: 20.7 KB
Line 
1unit UHtmlClasses;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 UXmlClasses, Classes, SysUtils, SpecializedList;
9
10type
11
12 { TDomainAddress }
13
14 TDomainAddress = class(TPersistent)
15 private
16 function GetAsString: string;
17 procedure SetAsString(const Value: string);
18 public
19 Levels: TListString;
20 constructor Create;
21 destructor Destroy; override;
22 property AsString: string read GetAsString write SetAsString;
23 end;
24
25 TAddrClass = (acA, acB, acC, acD, acE);
26
27 { TIpAddress }
28
29 TIpAddress = class(TPersistent)
30 private
31 function GetAddrClass: TAddrClass;
32 function GetAsCardinal: Cardinal;
33 function GetAsString: string;
34 function GetBroadcast: Boolean;
35 procedure SetBroadcast(const Value: Boolean);
36 procedure SetAsCardinal(const Value: Cardinal);
37 procedure SetAsString(const Value: string);
38 public
39 Octets: array[0..3] of Byte;
40 procedure Assign(Source: TPersistent); override;
41 function IsAddressString(Value: string): Boolean;
42 property AsCardinal: Cardinal read GetAsCardinal write SetAsCardinal;
43 property AsString: string read GetAsString write SetAsString;
44 property AddrClass: TAddrClass read GetAddrClass;
45 property Broadcast: Boolean read GetBroadcast write SetBroadcast;
46 end;
47
48 THostAddressState = (asDomainName, asIpAddress);
49 THostAddress = class(TPersistent)
50 private
51 function GetAsString: string;
52 procedure SetAsString(const Value: string);
53 public
54 State: THostAddressState;
55 DomainName: TDomainAddress;
56 IpAddress: TIpAddress;
57 constructor Create;
58 destructor Destroy; override;
59 property AsString: string read GetAsString write SetAsString;
60 end;
61
62 TURL = class(TPersistent)
63 private
64 function GetAsString: string;
65 procedure SetAsString(Value: string);
66 public
67 Scheme: string;
68 UserName: string;
69 Password: string;
70 Host: THostAddress;
71 Port: Word;
72 Path: string;
73 Query: string;
74 Fragment: string;
75 constructor Create;
76 destructor Destroy; override;
77 property AsString: string read GetAsString write SetAsString;
78 end;
79
80 { THtmlElement }
81
82 THtmlElement = class
83 protected
84 function GetAsXmlElement: TXmlElement; virtual;
85 public
86 Id: string;
87 Name: string;
88 ClassId: string;
89 Style: string;
90 procedure Assign(Source: THtmlElement); virtual;
91 property AsXmlElement: TXmlElement read GetAsXmlElement;
92 end;
93
94 TBlockType = (btNoTag, btBlockLevel, btInline);
95
96 { THtmlString }
97
98 THtmlString = class(THtmlElement)
99 private
100 function GetAsXmlElement: TXmlElement; override;
101 public
102 Text: string;
103 procedure Assign(Source: THtmlElement); override;
104 end;
105
106 { THtmlLineBreak }
107
108 THtmlLineBreak = class(THtmlElement)
109 private
110 function GetAsXmlElement: TXmlElement; override;
111 public
112 constructor Create;
113 end;
114
115 THtmlBlock = class(THtmlElement)
116 protected
117 function GetAsXmlElement: TXmlElement; override;
118 public
119 BlockType: TBlockType;
120 SubItems: TListObject; // TListObject<THtmlElement>;
121 constructor Create;
122 destructor Destroy; override;
123 end;
124
125 THtmlLink = class(THtmlElement)
126 private
127 function GetAsXmlElement: TXmlElement; override;
128 public
129 Target: TURL;
130 Content: THtmlElement;
131 constructor Create;
132 destructor Destroy; override;
133 end;
134
135 TSizeUnits = (suPixels, suPercents);
136
137 THtmlSize = record
138 Width: Integer;
139 Height: Integer;
140 Units: TSizeUnits;
141 end;
142
143 THtmlImage = class(THtmlElement)
144 private
145 function GetAsXmlElement: TXmlElement; override;
146 public
147 Size: THtmlSize;
148 Source: TURL;
149 AlternateText: string;
150 constructor Create;
151 destructor Destroy; override;
152 end;
153
154 THtmlInputType = (itText, itComboBox, itRadioButton, itReset, itPassword,
155 itSubmit, itHidden, itFileSelect, itButton, itCheckBox);
156
157 { THtmlInput }
158
159 THtmlInput = class(THtmlElement)
160 private
161 function GetAsXmlElement: TXmlElement; override;
162 public
163 InputType: THtmlInputType;
164 Value: Variant;
165 ItemName: string;
166 procedure Assign(Source: THtmlElement); override;
167 constructor Create;
168 destructor Destroy; override;
169 end;
170
171 { THtmlForm }
172
173 THtmlForm = class(THtmlBlock)
174 protected
175 function GetAsXmlElement: TXmlElement; override;
176 public
177 Method: string;
178 Action: TURL;
179 constructor Create;
180 destructor Destroy; override;
181 end;
182
183 THtmlDocument = class
184 private
185 function GetAsXmlDocument: TXmlDocument;
186 public
187 Title: string;
188 ContentEncoding: string;
189 ContentLanguage: string;
190 Body: THtmlBlock;
191 Styles: TStringList;
192 Scripts: TStringList;
193 property AsXmlDocument: TXmlDocument read GetAsXmlDocument;
194 constructor Create;
195 destructor Destroy; override;
196 end;
197
198 { THtmlCell }
199
200 THtmlCell = class(THtmlElement)
201 private
202 function GetAsXmlElement: TXmlElement; override;
203 public
204 RowSpan: Integer;
205 ColSpan: Integer;
206 Value: THtmlElement;
207 constructor Create;
208 destructor Destroy; override;
209 end;
210
211 { THtmlRow }
212
213 THtmlRow = class(THtmlElement)
214 private
215 function GetAsXmlElement: TXmlElement; override;
216 public
217 Cells: TListObject; // TListObject<THtmlCell>
218 constructor Create;
219 destructor Destroy; override;
220 end;
221
222 { THtmlTable }
223
224 THtmlTable = class(THtmlElement)
225 protected
226 function GetAsXmlElement: TXmlElement; override;
227 public
228 Rows: TListObject; // TListObject<THtmlRow>
229 constructor Create;
230 destructor Destroy; override;
231 end;
232
233 { TQueryString }
234
235 TQueryString = class
236 Data: TStringList;
237 procedure SetStringServer;
238 procedure SetString(QueryString: string);
239 function GetString: string;
240 constructor Create;
241 destructor Destroy; override;
242 end;
243
244implementation
245
246resourcestring
247 SStringToIPConversionError = 'String to IP address conversion error';
248
249
250function LeftCutString(var Source, Output: string; Delimiter: string; Allowed: string = ''): Boolean;
251var
252 I, J: Integer;
253 Matched: Boolean;
254begin
255 I := 1;
256 Matched := True;
257 while (I < Length(Source)) and Matched do begin
258 Matched := False;
259 if (Source[I] >= 'A') and (Source[I] <= 'Z') then Matched := True;
260 if (Source[I] >= 'a') and (Source[I] <= 'z') then Matched := True;
261 if (Source[I] >= '0') and (Source[I] <= '9') then Matched := True;
262 for J := 1 to Length(Allowed) do
263 if Source[I] = Allowed[J] then Matched := True;
264 if Matched then Inc(I);
265 end;
266 if (Delimiter = Copy(Source, I, Length(Delimiter))) or (I = Length(Source)) then begin
267 Output := Copy(Source, 1, I-1);
268 Delete(Source, 1, Length(Output) + Length(Delimiter));
269 Result := True;
270 end else begin
271 Output := '';
272 Result := False;
273 end;
274end;
275
276function RightCutString(var Source, Output: string; Delimiter: string; Allowed: string = ''): Boolean;
277var
278 I, J: Integer;
279 Matched: Boolean;
280begin
281 I := Length(Source);
282 Matched := True;
283 while (I > 0) and Matched do begin
284 Matched := False;
285 if (Source[I] >= 'A') and (Source[I] <= 'Z') then Matched := True;
286 if (Source[I] >= 'a') and (Source[I] <= 'z') then Matched := True;
287 if (Source[I] >= '0') and (Source[I] <= '9') then Matched := True;
288 for J := 1 to Length(Allowed) do
289 if Source[I] = Allowed[J] then Matched := True;
290 if Matched then Dec(I);
291 end;
292 if (Delimiter = Copy(Source, I - Length(Delimiter) + 1, Length(Delimiter))) or (I = 0) then begin
293 Output := Copy(Source, I+1, Length(Source) - I);
294 Delete(Source, I, Length(Output) + Length(Delimiter));
295 Result := True;
296 end else begin
297 Output := '';
298 Result := False;
299 end;
300end;
301
302{ THtmlCell }
303
304function THtmlCell.GetAsXmlElement: TXmlElement;
305begin
306 Result := inherited GetAsXmlElement;
307 TXmlTag(Result).Name := 'td';
308 with TXmlTag(Result).Attributes do begin
309 if ColSpan > 1 then Add('colspan', IntToStr(ColSpan));
310 if RowSpan > 1 then Add('rowspan', IntToStr(RowSpan));
311 end;
312 TXmlTag(Result).SubElements.Add(Value.AsXmlElement);
313end;
314
315constructor THtmlCell.Create;
316begin
317 ColSpan := 1;
318 RowSpan := 1;
319end;
320
321destructor THtmlCell.Destroy;
322begin
323 Value.Free;
324 inherited Destroy;
325end;
326
327{ THtmlRow }
328
329function THtmlRow.GetAsXmlElement: TXmlElement;
330var
331 Column: Integer;
332begin
333 Result := inherited GetAsXmlElement;
334 TXmlTag(Result).Name := 'tr';
335 for Column := 0 to Cells.Count - 1 do
336 TXmlTag(Result).SubElements.AddNew(THtmlCell(Cells[Column]).AsXmlElement);
337end;
338
339constructor THtmlRow.Create;
340begin
341 Cells := TListObject.Create;
342end;
343
344destructor THtmlRow.Destroy;
345begin
346 Cells.Free;
347 inherited Destroy;
348end;
349
350{ THtmlTable }
351
352function THtmlTable.GetAsXmlElement: TXmlElement;
353var
354 Row, Column: Integer;
355begin
356 Result := inherited;
357 with TXmlTag(Result) do begin
358 Name := 'table';
359 for Row := 0 to Rows.Count - 1 do
360 SubElements.AddNew(THtmlRow(Rows[Row]).AsXmlElement);
361 end;
362end;
363
364constructor THtmlTable.Create;
365begin
366 Rows := TListObject.Create;
367end;
368
369destructor THtmlTable.Destroy;
370begin
371 Rows.Free;
372 inherited Destroy;
373end;
374
375{ THtmlLineBreak }
376
377function THtmlLineBreak.GetAsXmlElement: TXmlElement;
378begin
379 Result := inherited GetAsXmlElement;
380 TXmlTag(Result).Name := 'br';
381end;
382
383constructor THtmlLineBreak.Create;
384begin
385end;
386
387{ THtmlInput }
388
389function THtmlInput.GetAsXmlElement: TXmlElement;
390var
391 InputTypeString: string;
392begin
393 Result := TXmlTag.Create;
394 with TXmlTag(Result) do begin
395 Name := 'input';
396 case InputType of
397 itButton: InputTypeString := 'button';
398 itRadioButton: InputTypeString := 'radio';
399 itCheckBox: InputTypeString := 'checkbox';
400 itText: InputTypeString := 'text';
401 itFileSelect: InputTypeString := 'file';
402 itSubmit: InputTypeString := 'submit';
403 itHidden: InputTypeString := 'hidden';
404 itPassword: InputTypeString := 'password';
405 end;
406 Attributes.Add('type', InputTypeString);
407 Attributes.Add('value', Value);
408 if Self.ItemName <> '' then
409 Attributes.Add('name', Self.ItemName);
410 end;
411end;
412
413procedure THtmlInput.Assign(Source: THtmlElement);
414begin
415 inherited Assign(Source);
416 InputType := THtmlInput(Source).InputType;
417 Value := THtmlInput(Source).Value;
418 ItemName := THtmlInput(Source).ItemName;
419end;
420
421constructor THtmlInput.Create;
422begin
423
424end;
425
426destructor THtmlInput.Destroy;
427begin
428 inherited Destroy;
429end;
430
431{ THtmlForm }
432
433function THtmlForm.GetAsXmlElement: TXmlElement;
434begin
435 Result := TXmlTag.Create;
436 with TXmlTag(Result) do begin
437 Name := 'form';
438 Attributes.Add('action', Action.AsString);
439 Attributes.Add('method', Method);
440 end;
441end;
442
443constructor THtmlForm.Create;
444begin
445 inherited;
446 Action := TURL.Create;
447 BlockType := btBlockLevel;
448 Method := 'get';
449end;
450
451destructor THtmlForm.Destroy;
452begin
453 Action.Free;
454 inherited Destroy;
455end;
456
457{ THtmlDocument }
458
459constructor THtmlDocument.Create;
460begin
461 Body := THtmlBlock.Create;
462 Styles := TStringList.Create;
463 Scripts := TStringList.Create;
464 ContentLanguage := 'en';
465 ContentEncoding := 'utf-8';
466end;
467
468destructor THtmlDocument.Destroy;
469begin
470 Body.Free;
471 Styles.Free;
472 Scripts.Free;
473 inherited;
474end;
475
476function THtmlDocument.GetAsXmlDocument: TXmlDocument;
477var
478 DocType: TXMLTag;
479 HTMLTag: TXMLTag;
480 I: Integer;
481begin
482 Result := TXmlDocument.Create;
483 with Result, Content do begin
484 DocType := TXMlTag.Create;
485 DocType.Name := '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"';
486 Doctype.EndTagSymbol := '';
487 SubElements.Add(DocType);
488 HTMLTag := TXMLTag.Create;
489 with HTMLTag do begin
490 Name := 'html';
491 with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
492 Name := 'head';
493 with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
494 Name := 'title';
495 with TXmlString(SubElements[SubElements.Add(TXmlString.Create)]) do begin
496 Text := Title;
497 end;
498 end;
499 with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
500 Name := 'meta';
501 Attributes.Add('http-equiv', 'Content-Language');
502 Attributes.Add('content', ContentLanguage);
503 end;
504 with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
505 Name := 'meta';
506 Attributes.Add('http-equiv', 'Content-Type');
507 Attributes.Add('content', 'text/html; charset=' + ContentEncoding);
508 end;
509 for I := 0 to Styles.Count - 1 do
510 with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
511 Name := 'link';
512 Attributes.Add('rel', 'stylesheet');
513 Attributes.Add('href', Styles[I]);
514 Attributes.Add('type', 'text/css');
515 Attributes.Add('media', 'all');
516 end;
517 for I := 0 to Scripts.Count - 1 do
518 with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
519 Name := 'script';
520 ShringEmpty := False;
521 Attributes.Add('type', 'text/javascript');
522 Attributes.Add('src', Scripts[I]);
523 end;
524 end;
525 with TXmlTag(SubElements[SubElements.Add(TXmlTag.Create)]) do begin
526 Name := 'body';
527 SubElements.Add(Body.AsXmlElement);
528 end;
529 end;
530 SubElements.Add(HTMLTag);
531 end;
532end;
533
534{ THtmlBlock }
535
536constructor THtmlBlock.Create;
537begin
538 inherited;
539 SubItems := TListObject.Create;
540end;
541
542destructor THtmlBlock.Destroy;
543begin
544 SubItems.Free;
545 inherited;
546end;
547
548function THtmlBlock.GetAsXmlElement: TXmlElement;
549var
550 I: Integer;
551begin
552 Result := TXmlTag.Create;
553 with TXmlTag(Result) do begin
554 case BlockType of
555 btBlockLevel: Name := 'div';
556 btInline: Name := 'span';
557 btNoTag: Name := '';
558 end;
559 for I := 0 to SubItems.Count - 1 do
560 SubElements.Add(THtmlElement(SubItems[I]).AsXmlElement);
561 end;
562end;
563
564{ THtmlElement }
565
566function THtmlElement.GetAsXmlElement: TXmlElement;
567begin
568 Result := TXmlTag.Create;
569 with TXmlTag(Result).Attributes do begin
570 if Name <> '' then Add('name', Name);
571 if Style <> '' then Add('style', Style);
572 if ClassId <> '' then Add('class', ClassId);
573 if Id <> '' then Add('id', Id);
574 end;
575end;
576
577procedure THtmlElement.Assign(Source: THtmlElement);
578begin
579 Id := Source.Id;
580 Name := Source.Name;
581 ClassId := Source.ClassId;
582 Style := Source.Style;
583end;
584
585{ TIpAddress }
586
587procedure TIpAddress.Assign(Source: TPersistent);
588var
589 I: Integer;
590begin
591 if Assigned(Source) then begin
592 if Source is TIpAddress then begin
593 for I := 0 to High(Octets) do
594 Octets[I] := TIpAddress(Source).Octets[I];
595 end else inherited;
596 end else inherited;
597end;
598
599function TIpAddress.IsAddressString(Value: string): Boolean;
600var
601 Parts: TListString;
602begin
603 Result := True;
604 try
605 Parts := TListString.Create;
606 Parts.Explode(Value, '.', StrToStr);
607 if Parts.Count = 4 then begin
608 if (StrToInt(Parts[3]) < 0) or (StrToInt(Parts[3]) > 255) then Result := False;
609 if (StrToInt(Parts[2]) < 0) or (StrToInt(Parts[2]) > 255) then Result := False;
610 if (StrToInt(Parts[1]) < 0) or (StrToInt(Parts[1]) > 255) then Result := False;
611 if (StrToInt(Parts[0]) < 0) or (StrToInt(Parts[0]) > 255) then Result := False;
612 end else Result := False;
613 finally
614 Parts.Free;
615 end;
616end;
617
618function TIpAddress.GetAddrClass: TAddrClass;
619begin
620 if (Octets[3] and $80) = 0 then Result := acA
621 else begin
622 if (Octets[3] and $40) = 0 then Result := acB
623 else begin
624 if (Octets[3] and $20) = 0 then Result := acC
625 else begin
626 if (Octets[3] and $10) = 0 then Result := acD
627 else Result := acE;
628 end;
629 end;
630 end;
631end;
632
633function TIpAddress.GetAsCardinal: Cardinal;
634begin
635 Result := Octets[0] or (Octets[1] shl 8) or (Octets[2] shl 16) or (Octets[3] shl 24);
636end;
637
638function TIpAddress.GetAsString: string;
639begin
640 Result := IntToStr(Octets[3]) + '.' + IntToStr(Octets[2]) + '.' +
641 IntToStr(Octets[1]) + '.' + IntToStr(Octets[0]);
642end;
643
644function TIpAddress.GetBroadcast: Boolean;
645begin
646 Result := AsCardinal = High(Cardinal);
647end;
648
649procedure TIpAddress.SetAsCardinal(const Value: Cardinal);
650begin
651 Octets[0] := Byte(Value);
652 Octets[1] := Byte(Value shr 8);
653 Octets[2] := Byte(Value shr 16);
654 Octets[3] := Byte(Value shr 24);
655end;
656
657procedure TIpAddress.SetAsString(const Value: string);
658var
659 Parts: TListString;
660begin
661 try
662 Parts := TListString.Create;
663 Parts.Explode(Value, '.', StrToStr);
664 try
665// if Length(Parts) = 4 then begin
666 Octets[0] := StrToInt(Parts[3]);
667 Octets[1] := StrToInt(Parts[2]);
668 Octets[2] := StrToInt(Parts[1]);
669 Octets[3] := StrToInt(Parts[0]);
670// end else raise EConvertError.Create('String to IP address conversion error');
671 except
672 raise EConvertError.Create(SStringToIPConversionError);
673 end;
674 finally
675 Parts.Free;
676 end;
677end;
678
679procedure TIpAddress.SetBroadcast(const Value: Boolean);
680begin
681 AsCardinal := High(Cardinal);
682end;
683
684constructor TURL.Create;
685begin
686 Host := THostAddress.Create;
687end;
688
689destructor TURL.Destroy;
690begin
691 Host.Free;
692 inherited;
693end;
694
695function TURL.GetAsString: string;
696begin
697 Result := '';
698 if Scheme <> '' then Result := Scheme + '://';
699 if UserName <> '' then begin
700 Result := Result + UserName;
701 if UserName <> '' then Result := Result + ':' + Password;
702 Result := Result + '@';
703 end;
704 if Host.AsString <> '' then Result := Result + Host.AsString;
705 if Port <> 0 then Result := Result + ':' + IntToStr(Port);
706 if Path <> '' then Result := Result + Path;
707 if Query <> '' then Result := Result + '?' + Query;
708 if Fragment <> '' then Result := Result + '#' + Fragment;
709end;
710
711procedure TURL.SetAsString(Value: string);
712var
713 HostAddr: string;
714 HostPort: string;
715begin
716 LeftCutString(Value, Scheme, '://');
717 if LeftCutString(Value, UserName, ':') then LeftCutString(Value, Password, '@')
718 else LeftCutString(Value, UserName, '@');
719 RightCutString(Value, Fragment, '#');
720 RightCutString(Value, Query, '?', '=&');
721 if LeftCutString(Value, HostAddr, ':', '.') then begin
722 LeftCutString(Value, HostPort, '');
723 Port := StrToInt(HostPort);
724 end else LeftCutString(Value, HostAddr, '', '.');
725 Host.AsString := HostAddr;
726 LeftCutString(Value, Path, '', '/.');
727end;
728
729
730{ TDomainAddress }
731
732function TDomainAddress.GetAsString: string;
733begin
734 try
735 Levels.Reverse;
736 Result := Levels.Implode('.', StrToStr);
737 finally
738 Levels.Reverse;
739 end;
740end;
741
742procedure TDomainAddress.SetAsString(const Value: string);
743begin
744 Levels.Explode(Value, '.', StrToStr);
745 Levels.Reverse;
746end;
747
748constructor TDomainAddress.Create;
749begin
750 Levels := TListString.Create;
751end;
752
753destructor TDomainAddress.Destroy;
754begin
755 Levels.Free;
756 inherited Destroy;
757end;
758
759{ THtmlLink }
760
761constructor THtmlLink.Create;
762begin
763 Target := TURL.Create;
764end;
765
766destructor THtmlLink.Destroy;
767begin
768 Target.Free;
769 inherited;
770end;
771
772function THtmlLink.GetAsXmlElement: TXmlElement;
773begin
774 Result := TXmlTag.Create;
775 with TXmlTag(Result) do begin
776 Name := 'a';
777 Attributes.Add('href', Target.AsString);
778 if Assigned(Content) then SubElements.Add(Content.AsXmlElement);
779 end;
780end;
781
782{ THtmlString }
783
784function THtmlString.GetAsXmlElement: TXmlElement;
785begin
786 Result := TXmlString.Create;
787 TXmlString(Result).Text := Text;
788end;
789
790procedure THtmlString.Assign(Source: THtmlElement);
791begin
792 inherited Assign(Source);
793 Text := THtmlString(Source).Text;
794end;
795
796{ THostAddress }
797
798constructor THostAddress.Create;
799begin
800 DomainName := TDomainAddress.Create;
801 IpAddress := TIpAddress.Create;
802 State := asDomainName;
803 DomainName.AsString := 'localhost';
804end;
805
806destructor THostAddress.Destroy;
807begin
808 DomainName.Free;
809 IpAddress.Free;
810 inherited;
811end;
812
813function THostAddress.GetAsString: string;
814begin
815 case State of
816 asDomainName: Result := DomainName.AsString;
817 asIpAddress: Result := IpAddress.AsString;
818 end;
819end;
820
821procedure THostAddress.SetAsString(const Value: string);
822begin
823 if IpAddress.IsAddressString(Value) then begin
824 State := asIpAddress;
825 IpAddress.AsString := Value;
826 end else begin
827 State := asDomainName;
828 DomainName.AsString := Value;
829 end;
830end;
831
832{ THtmlImage }
833
834constructor THtmlImage.Create;
835begin
836 Source := TURL.Create;
837end;
838
839destructor THtmlImage.Destroy;
840begin
841 Source.Free;
842 inherited;
843end;
844
845function THtmlImage.GetAsXmlElement: TXmlElement;
846begin
847 Result := TXmlTag.Create;
848 with TXmlTag(Result) do begin
849 Name := 'img';
850 Attributes.Add('src', Source.AsString);
851 Attributes.Add('width', IntToStr(Size.Width));
852 Attributes.Add('height', IntToStr(Size.Height));
853 Attributes.Add('alt', AlternateText);
854 end;
855end;
856
857procedure TQueryString.SetStringServer;
858begin
859 //$this->SetString($_SERVER['QUERY_STRING']);
860end;
861
862procedure TQueryString.SetString(QueryString: string);
863begin
864 (*
865 $this->Data = array();
866 $Parts = explode('&', $QueryString);
867 foreach($Parts as $Part)
868 {
869 if($Part != '')
870 {
871 $Item = explode('=', $Part);
872 $this->Data[$Item[0]] = $Item[1];
873 end;
874 end;*)
875end;
876
877function TQueryString.GetString: string;
878begin
879 (*$Parts = array();
880 foreach($this->Data as $Index => $Item)
881 {
882 $Parts[] = $Index.'='.$Item;
883 }
884 return(implode('&', $Parts));*)
885end;
886
887constructor TQueryString.Create;
888begin
889 Data := TStringList.Create;
890end;
891
892destructor TQueryString.Destroy;
893begin
894 Data.Free;
895 inherited Destroy;
896end;
897
898end.
Note: See TracBrowser for help on using the repository browser.