Subversion Repositories jumper

Rev

Rev 11 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit Functions;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, Dialogs, Graphics, Classes, ExtCtrls;
  7.  
  8. function ExtractFileNameWithoutExt(filename: string): string;
  9. procedure ClearImage(Image: TImage; BackgroundColor: TColor);
  10. function Explode(Separator, Text: String): TStringList;
  11. function Position(FullString, Search: String): Integer;
  12. function DotsAtBeginning(s: string): integer;
  13. function DotsAtEnd(s: string): integer;
  14.  
  15. implementation
  16.  
  17. function ExtractFileNameWithoutExt(filename: string): string;
  18. begin
  19.   result := ExtractFileName(filename);
  20.   result := copy(result, 1, Length(result)-Length(ExtractFileExt(result)));
  21. end;
  22.  
  23. procedure ClearImage(Image: TImage; BackgroundColor: TColor);
  24. var
  25.   OldPenColor, OldBrushColor: TColor;
  26. begin
  27.   OldPenColor := Image.Canvas.Pen.Color;
  28.   OldBrushColor := Image.Canvas.Brush.Color;
  29.   Image.Canvas.Pen.Color := BackgroundColor;
  30.   Image.Canvas.Brush.Color := BackgroundColor;
  31.   Image.Canvas.Rectangle(0, 0, Image.Width, Image.Height);
  32.   Image.Canvas.Pen.Color := OldPenColor;
  33.   Image.Canvas.Brush.Color := OldBrushColor;
  34. end;
  35.  
  36. function Explode(Separator, Text: String): TStringList;
  37. var
  38.   pos: integer;
  39.   tmp: string;
  40. begin
  41.   result := TStringList.Create;
  42.  
  43.   while Length(Text) > 0 do
  44.   begin
  45.     pos := Functions.Position(Text, Separator);
  46.  
  47.     if pos = -1 then
  48.     begin
  49.       tmp := Text;
  50.       Text := '';
  51.     end
  52.     else
  53.     begin
  54.       tmp := copy(Text, 1, pos-1);
  55.       Text := copy(Text, pos+1, Length(Text)-pos);
  56.     end;
  57.  
  58.     result.Add(tmp);
  59.   end;
  60. end;
  61.  
  62. function Position(FullString, Search: String): Integer;
  63. var
  64.   x: Integer;
  65. begin
  66.   x := Length(StrPos(PChar(FullString), PChar(Search)));
  67.   if x = 0 then
  68.     result := -1
  69.   else
  70.     result := Length(FullString) - x + 1;
  71. end;
  72.  
  73. function DotsAtBeginning(s: string): integer;
  74. var
  75.   i: integer;
  76. begin
  77.   result := 0;
  78.   for i := 1 to Length(s) do
  79.   begin
  80.     if s[i] = '.' then
  81.       Inc(result)
  82.     else
  83.       Exit;
  84.   end;
  85. end;
  86.  
  87. function DotsAtEnd(s: string): integer;
  88. var
  89.   i: integer;
  90. begin
  91.   result := 0;
  92.   for i := Length(s) downto 1 do
  93.   begin
  94.     if s[i] = '.' then
  95.       Inc(result)
  96.     else
  97.       Exit;
  98.   end;
  99. end;
  100.  
  101. end.
  102.