⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brkapart.pas

📁 Well known and usefull component for delphi 7
💻 PAS
字号:
{ -------------------------------------------------------------------------------------}
{ A "break apart strings" component for Delphi32.                                      }
{ Copyright 1999-2001, Patrick Brisacier and Jean-Fabien Connault. All Rights Reserved.}
{ This component can be freely used and distributed in commercial and private          }
{ environments, provided this notice is not modified in any way.                       }
{ -------------------------------------------------------------------------------------}
{ Feel free to contact us if you have any questions, comments or suggestions at:       }
{   cycocrew@worldnet.fr (Jean-Fabien Connault)                                        }
{ You can always find the latest version of this component at:                         }
{   http://www.worldnet.net/~cycocrew/delphi/                                          }
{ -------------------------------------------------------------------------------------}
{ Date last modified:  07-Jun-02 (Gtrant@heidi.ie)                                     }
{ -------------------------------------------------------------------------------------}

{ -------------------------------------------------------------------------------------}
{ TBrkApart v1.02                                                                      }
{ -------------------------------------------------------------------------------------}
{ Description:                                                                         }
{   A component that allows you to break apart strings.                                }
{ Properties:                                                                          }
{   property BreakString: String;                                                      }
{   property BaseString: String;                                                       }
{   property AllowEmptyString: Boolean;                                                }
{   property StringList: TStringList;                                                  }
{ Procedures and functions:                                                            }
{   procedure BreakApart;                                                              }
{   procedure ReverseBreakApart;                                                       }
{                                                                                      }
{ See example contained in example.zip file for more details.                          }
{ -------------------------------------------------------------------------------------}
{ Revision History:                                                                    }
{ 1.00:  + Initial release                                                             }
{ 1.01:  + Added CaseSensitive property                                                }
{ 1.02:  + Changed Register page to "System" (06/16/01)                                }
{ 1.03:  + Added support for Keeping Delimiter and stragglers (07-Jun-02)              }
{ -------------------------------------------------------------------------------------}

unit Brkapart;

interface

uses
  SysUtils,  WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs;

type
{$IFDEF OBJECTS_ONLY}
  TBrkApart = class
{$ELSE}
  TBrkApart = class(TComponent)
{$ENDIF}
  private
    { Private-d閏larations }
    FAllowEmptyString: Boolean;
    FKeepDelimiter: Boolean;
    FStraggler:String; // This would be a string at the end of the list without a delimiter at its end.
    FBaseString: string;
    FBreakString: string;
    FCaseSensitive: Boolean;
    FStringList: TStringList;
    FBreakList: TStringList;
    procedure SetStringList(AStringList: TStringList);
    procedure SetBreakList(ABreakList: TStringList);
  protected
    { Protected-d閏larations }
  public
    { Public-d閏larations }
    constructor sCreate;
{$IFDEF OBJECTS_ONLY}
    constructor Create;
{$ELSE}
    constructor Create(AOwner:TComponent); override;
{$ENDIF}
    destructor Destroy; override;
    procedure BreakApart;
    procedure ReverseBreakApart;
  published
    { Published-d閏larations }
    property AllowEmptyString: Boolean read FAllowEmptyString write FAllowEmptyString;
    Property KeepDelimiter: Boolean read FKeepDelimiter write FKeepDelimiter;
    Property Straggler: String read FStraggler write FStraggler;
    property BreakString: string read FBreakString write FBreakString;
    property BreakList: TStringList read FBreakList write SetBreakList;
    property BaseString: string read FBaseString write FBaseString;
    property CaseSensitive: Boolean read FCaseSensitive write FCaseSensitive;
    property StringList: TStringList read FStringList write SetStringList;
  end;

{$IFNDEF OBJECTS_ONLY}
procedure Register;
{$ENDIF}

implementation

{*****************************************************************************}
{* PROCEDURE Register                                                        *}
{*****************************************************************************}

{$IFNDEF OBJECTS_ONLY}
procedure Register;
begin
  RegisterComponents('Heidi', [TBrkApart]);
end;
{$ENDIF}

{*****************************************************************************}
{* CONSTRUCTOR                                                               *}
{*****************************************************************************}
{$IFNDEF OBJECTS_ONLY}
constructor TBrkApart.Create(AOwner: TComponent);
{$ELSE}
constructor TBrkApart.Create;
{$ENDIF}
begin
{$IFNDEF OBJECTS_ONLY}
  inherited Create(AOwner);
{$ENDIF}
  FStringList := TStringList.Create;
end;
{*****************************************************************************}
{* CONSTRUCTOR                                                               *}
{*****************************************************************************}
constructor TBrkApart.sCreate;
begin
  FStringList := TStringList.Create;
end;

{*****************************************************************************}
{* DESTRUCTOR                                                                *}
{*****************************************************************************}

destructor TBrkApart.Destroy;
begin
  FStringList.Free;
  inherited Destroy;
end;

{*****************************************************************************}
{* PROCEDURE SetStringList                                                   *}
{*****************************************************************************}

procedure TBrkApart.SetStringList(AStringList: TStringList);
begin
  FStringList.Assign(AStringList);
end;

{*****************************************************************************}
{* PROCEDURE SetStringList                                                   *}
{*****************************************************************************}

procedure TBrkApart.SetBreakList(ABreakList: TStringList);
begin
  FBreakList.Assign(ABreakList);
end;

{*****************************************************************************}
{* PROCEDURE BreakApart                                                      *}
{*****************************************************************************}

procedure TBrkApart.BreakApart;
var
  EndOfCurrentString: Integer;
  TempStr, TempBaseString: string;
begin
  FStringList.Clear;
  TempBaseString := FBaseString;
  repeat
    if FCaseSensitive then
       EndOfCurrentString := Pos(FBreakString, TempBaseString)
    else
       EndOfCurrentString := Pos(lowerCase(FBreakString), lowerCase(TempBaseString));

    if EndOfCurrentString = 0 then
    Begin
      TempStr := TempBaseString;
      FStraggler := TempStr;
    End
    else
    Begin
      TempStr := Copy(TempBaseString, 1, EndOfCurrentString - 1);
      If FKeepDelimiter = True then TempStr := TempStr + FBreakString;
    End;

    if ((TempStr = '') and FAllowEmptyString) or (TempStr <> '') then
      FStringList.add(TempStr);

    TempBaseString := Copy(TempBaseString, EndOfCurrentString + length(FBreakString),
      length(TempBaseString) - EndOfCurrentString);
  until EndOfCurrentString = 0;
end;

{*****************************************************************************}
{* PROCEDURE ReverseBreakApart                                               *}
{*****************************************************************************}

procedure TBrkApart.ReverseBreakApart;
var
  i: Integer;
begin
  if FStringList.Count > 0 then
  begin
    FBaseString := FStringList[0];
    for i := 1 to FStringList.Count - 1 do
      if ((FStringList[i] = '') and FAllowEmptyString) or (FStringList[i] <> '') then
        FBaseString := FBaseString + FBreakString + FStringList[i];
  end
  else
    FBaseString := '';
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -