Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TSaveDialog "The FilterIndex appear non equal to FileName Extension" !!!!

36 views
Skip to first unread message

pop3050

unread,
Mar 7, 2011, 4:55:12 PM3/7/11
to
void __fastcall TMainForm::SaveDialog1TypeChange(TObject *Sender)
{
AnsiString FileExt,FileName,Filter;
FileExt = ExtractFileExt(this->SaveDialog1->FileName);
FileName = ExtractFileName(this->SaveDialog1->FileName);
//FilePath = ExtractFilePath(this->SaveDialog1->FileName);
Filter = this->SaveDialog1->Filter;

char *first,*last,*Ext,*dot,*Name,*Fil;

Fil = new char[Filter.Length()+1];
Fil = Filter.c_str();
//strcpy2(Fil,Filter.c_str());

Name= new char[FileName.Length()+1];
strcpy2(Name,FileName.c_str());

dot=strrchr2(Name,'.');
while(dot){
Name[dot-Name]='\0';
FileName = Name;
dot=strrchr2(Name,'.');
}
if(FileExt.Length()!=0){
if(FileExt == ".txt")
this->SaveDialog1->FilterIndex = 2;
if(FileExt == ".rtf")
this->SaveDialog1->FilterIndex = 3;
Ext = new char[FileExt.Length()+1];
Ext = FileExt.c_str();
goto continu;
}
switch(this->SaveDialog1->FilterIndex){
case 1: first=strchr2(Fil,'|');
last=strchr2(first+1,'|');

Ext = new char[last-first];
strncpy2(Ext,first+2,(last-first)-2);

FileExt = Ext;
break;
case 2: first=strchr2(Fil,'|');
last=strchr2(first+1,'|');
first=strchr2(last+1,'|'); last=strchr2(first+1,'|');

Ext = new char[last-first];
strncpy2(Ext,first+2,(last-first)-2);

FileExt = Ext;
break;
case 3: first=strchr2(Fil,'|');
last=strchr2(first+1,'|');
first=strchr2(last+1,'|'); last=strchr2(first+1,'|');
first=strchr2(last+1,'|'); //last=strchr2(first+1,'|');

Ext = new char[StrLen(first)+1];
strcpy2(Ext,first+2);

FileExt = Ext;
default:;
}
continu:
delete[] Fil; //first et last pointent sur Fil.
if(FileExt != ".*"){
strcat2(Name,Ext);
FileName = Name; //function ChangeFileExt(const FileName: string;
const Extension: string): string;
this->SaveDialog1->FileName = FileName;
}
delete[] Ext;
delete[] Name;
}

0 new messages