• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

read from the txt file

carry on from my last Q sorry...

If when the form13 loads in the onshow event, how would i have it so that if the email inside DBemail.text is already inside the text file, dont add it... this is what i am working with


if
DBemail.text=(f:\special.txt')
then begin
showmessage('already added')
  MakeSpecialMember1.enabled := false
  end
  else begin
    MakeSpecialMember1.enabled := true ;


( i know its wrong, just so it gives the idea )
0
boycoder
Asked:
boycoder
1 Solution
 
Ephraim WangoyaCommented:

Make a function to open the file and check for the email
function EmailInFile(const AFileName, AEmail: string): Boolean;
var
  FileList: TStringList;
begin
  FileList := TStringList.Create;
  try
    FileList.LoadFromFile(AFileName);
    Result := Pos(LowerCase(Trim(AEmail)), LowerCase(FileList.Text)) > 0;
  finally
    FreeAndNil(FileList);
  end;
end;

//call it like this
if EmailInFile('f:\special.txt', DBemail.text) then
begin
  showmessage('already added')
  MakeSpecialMember1.enabled := false
end
else 
begin
    MakeSpecialMember1.enabled := true ; 
    ............
end;

Open in new window

0
 
boycoderAuthor Commented:
great!

notes incase i read this again..  i used it inside the actual sepcial select button rather than form show/createect..

Thanks friend.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now