Delphi Programming
Advertisement

Copy Function[]

Unit System

Description[]

There are 2 different copy functions.

Definition (Delphi 6):

function Copy(S; Index, Count: Integer): string;
function Copy(S; Index, Count: Integer): array;

Strings: Copy function is used to copy a substring from source String(S).
The result is a substring which starts at the given Index and Count is length of the substring.

Arrays: Copy function is used to copy a subarray from the source array(S).
The result is a subarray which starts at the given Index and Count is number of elements to copy from the source array.

Technical Comments[]

The Copy function structure are:: Copy( String,Index,Count );
The Copy function contents are:: Copy( String,Integer,Integer );

  1. Copy: Calls the function
  2. String: Text content passed to be copyed
  3. Index: Start position by character where the function must to start count the copy function
  4. Count: Number of characters to be copyed within the function as the result.

More complicated combinations of code can work better any possible results for your projects.

Examples[]

Examples must have on the form one or more TEdit and TButton components with its default names.

  • Edit1 must have a text set for 'Testing the Copy function';
  • for test the examples copy and paste the codes on the OnClick event for Button1.


Using the Copy function.[]



This function will copy part of a text from Edit1
and show the result in a message function.



ShowMessage( Copy( Edit1.text, 1, 7 );
//Show in result the word "Testing"



ShowMessage( Copy( Edit1.text, 18, 8 );
//Show in result the word "function"



No aditional information.



See Also[]

User Comments/Tips[]

WDHellS

Advertisement