本文整理汇总了C++中AnsiString::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ AnsiString::SetLength方法的具体用法?C++ AnsiString::SetLength怎么用?C++ AnsiString::SetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnsiString
的用法示例。
在下文中一共展示了AnsiString::SetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WMDropFiles
//---------------------------------------------------------------------------
void __fastcall TRefEditForm::WMDropFiles(TWMDropFiles &message)
{
AnsiString FileName;
FileName.SetLength(MAX_PATH);
int Count = DragQueryFile((HDROP)message.Drop, 0xFFFFFFFF, NULL, MAX_PATH);
// index through the files and query the OS for each file name...
for (int index = 0; index < Count; ++index)
{
// the following code gets the FileName of the dropped file. I know it
// looks cryptic but that's only because it is. Hey, Why do you think
// Delphi and C++ Builder are so popular anyway?
FileName.SetLength(DragQueryFile((HDROP)message.Drop, index,
FileName.c_str(), MAX_PATH));
// examine the filename's extension.
// If it's a Word file then ...
if (UpperCase(ExtractFileExt(FileName)) == ".DOC")
{
ListBox_Words->Items->Add(FileName);
}
}
// tell the OS that we're finished...
DragFinish((HDROP) message.Drop);
}
示例2: if
// fires an event when a file, or files are dropped onto the application.
void __fastcall TForm1::WMDropFiles(TWMDropFiles &message)
{ AnsiString FileName;
FileName.SetLength(MAX_PATH);
FileName.SetLength(DragQueryFile((HDROP)message.Drop, 0,FileName.c_str(), MAX_PATH));
if(UpperCase(ExtractFileExt(FileName)) == ".BMP")
{ bmp->LoadFromFile(FileName) ;
img->Picture->Bitmap->Assign(bmp) ;
} else if(UpperCase(ExtractFileExt(FileName)) == ".JPG")
{ TJPEGImage * jpeg = new TJPEGImage();
jpeg->LoadFromFile(FileName);
jpeg->DIBNeeded();
bmp->Assign(jpeg);
img->Picture->Bitmap->Assign(bmp) ;
delete jpeg;
}
preview->frmSelect->Position = 0 ;
outType->ItemIndex = 1 ;
if(preview->Visible) updatePreview();
int l = bmp->Width, h = bmp->Height ;
transType->ItemIndex = 0 ;
//preview->TransparentColor = 0 ;
// auto compute frame number and frameset way
if(l < 142 || h < 142)
{
int s ; int yyop ; int *v=&h, *vh=&l ;
if(l > h*2) { v=&l ; vh=&h ; vertical=0 ; } // horizontal frameset
else vertical = 1 ;
flipWay->Checked = !vertical ;
s = *vh + 3 ;
do { yyop = (*v)/s ; } while(s && yyop*s-- != *v) ; ++s ;
if(s < 4)
{ frmNb->Text = 1 ;
sprintf(msg,"frames of %i*%i",l,h) ;
LabelSize->Caption = msg ; fsx = l ; fsy = h ;
}
else {nb = yyop ; fsx = s ; fsy = *vh ;
frmNb->Text = yyop ;
sprintf(msg,"frames of %i*%i",s,*vh) ;
LabelSize->Caption = msg ;
}
} else { frmNb->Text = 1 ;
sprintf(msg,"frames of %i*%i",l,h) ;
LabelSize->Caption = msg ;
nb=1 ;
}
preview->ClientHeight = h ;
preview->ClientWidth = l + (nb > 1)*15 ;
preview->Caption = FileName + " (" + nb + ")" ;
fname = FileName ;
outTypeChange((TObject*)42) ;
Form1->Button1->Enabled = 1 ;
Form1->Height = 304 ;
Form1->StatusBar->Visible = 1 ;
// tell the OS that you're finished...
DragFinish((HDROP) message.Drop);
}
示例3: ReadDataFromRegistry
//===========================================================================
void Tform_Main::ReadDataFromRegistry()
{
AnsiString Name;
TRegistry *Reg = NULL;
try {
try {
Reg = new TRegistry;
AnsiString appName = ExtractFileName(Application->ExeName);
appName.SetLength(appName.Length() - 4);
Reg->RootKey = HKEY_LOCAL_MACHINE;
Reg->OpenKey("Software\\InnalabsUA\\ccg_QFactor", true);
DFT_DeltaFreq = Reg->ReadFloat("DFT_DeltaFreq");
DTF_InterpolationPointsCount = Reg->ReadInteger("DTF_InterpolationPointsCount");
FFT_MaxPointsCount = Reg->ReadInteger("FFT_MaxPointsCount");
SoundCardIndex = Reg->ReadInteger("SoundCardIndex");
FreqSoundCardIndex = Reg->ReadInteger("FreqSoundCardIndex");
} catch ( ... ){
Reg->CloseKey();
SaveDataToRegistry();
}
} __finally {
Reg->CloseKey();
if (Reg != NULL)
delete Reg;
}
}
示例4: LoadIniFile
void Global::LoadIniFile(AnsiString asFileName)
{
int i;
for (i = 0; i < 10; ++i)
{ // zerowanie pozycji kamer
pFreeCameraInit[i] = vector3(0, 0, 0); // wspó³rzêdne w scenerii
pFreeCameraInitAngle[i] = vector3(0, 0, 0); // k¹ty obrotu w radianach
}
TFileStream *fs;
fs = new TFileStream(asFileName, fmOpenRead | fmShareCompat);
if (!fs)
return;
AnsiString str = "";
int size = fs->Size;
str.SetLength(size);
fs->Read(str.c_str(), size);
// str+="";
delete fs;
TQueryParserComp *Parser;
Parser = new TQueryParserComp(NULL);
Parser->TextToParse = str;
// Parser->LoadStringToParse(asFile);
Parser->First();
ConfigParse(Parser);
delete Parser; // Ra: tego jak zwykle nie by³o wczeœniej :]
};
示例5: LoadFormPos
//---------------------------------------------------------------------------
void __fastcall LoadFormPos(TForm *Form,
const AnsiString IniFileName,
const AnsiString SectionName,
const AnsiString KeyName)
{
TIniFile *IniFile;
AnsiString sWindowPositions;
if (IniFileName.Length() == 0)
return;
// Create inifile object => Open ini file
IniFile = new TIniFile(IniFileName);
// Formatage par défaut de la ligne de la section window
sWindowPositions.SetLength(256);
WindowPosToStr(sWindowPositions.c_str(), Form);
// Get widow's position and size from ini file
sWindowPositions = IniFile->ReadString(SectionName,
KeyName,
sWindowPositions);
StrToWindowPos(sWindowPositions.c_str(), Form);
// Destroy inifile object => close ini file
IniFile->Free();
}
示例6: CallDllButtonClick
//---------------------------------------------------------------------------
void __fastcall TDllTestForm::CallDllButtonClick(TObject *Sender)
{
AnsiString Buffer;
int BufSize;
int Status;
Display("Calling DLL...");
BufSize = 100;
Buffer.SetLength(BufSize);
Status = IcsDllDemo(AnsiString(HostnameEdit->Text).c_str(),
AnsiString(PortEdit->Text).c_str(),
&Buffer[1], &BufSize);
Buffer.SetLength(BufSize);
if (Status)
Display("Error #" + IntToStr(Status));
Display(Buffer);
Display("Done with DLL");
}
示例7: W2MB
/**
* @brief Encoding wide to multibyte std::string
* @param $src UnicodeString
* @param $cp code page
* @return multibyte std::string
*/
AnsiString W2MB(const wchar_t * src, const UINT cp)
{
// assert(src);
if (!src || !*src)
{
return AnsiString("");
}
intptr_t reqLength = WideCharToMultiByte(cp, 0, src, -1, 0, 0, nullptr, nullptr);
AnsiString Result;
if (reqLength)
{
Result.SetLength(reqLength);
WideCharToMultiByte(cp, 0, src, -1, const_cast<LPSTR>(Result.c_str()),
static_cast<int>(reqLength), nullptr, nullptr);
Result.SetLength(Result.Length() - 1); //remove NULL character
}
return Result; //.c_str();
}
示例8: if
String TSearchFilesFrm::GetSearchData()
{
AnsiString data;
AnsiString content_text = edtSearchContent->Text;
if(cbSearchMode->ItemIndex == 0)
{
data = content_text;
}
else if(cbSearchMode->ItemIndex == 1)
{
data = BinToStr(content_text.c_str(), content_text.Length());
}
else if(cbSearchMode->ItemIndex == 2)
{
DWORD num = content_text.ToInt();
data.SetLength(4);
int pos = 0;
WriteDWORD(data.c_str(), pos, num);
data = BinToStr(data.c_str(), data.Length());
}
else if(cbSearchMode->ItemIndex == 3)
{
WORD num = content_text.ToInt();
data.SetLength(2);
int pos = 0;
WriteWORD(data.c_str(), pos, num);
data = BinToStr(data.c_str(), data.Length());
}
else if(cbSearchMode->ItemIndex == 4)
{
BYTE num = content_text.ToInt();
data.SetLength(1);
int pos = 0;
WriteBYTE(data.c_str(), pos, num);
data = BinToStr(data.c_str(), data.Length());
}
return data;
}
示例9: TForm
//---------------------------------------------------------------------------
__fastcall TfrmAbout::TfrmAbout(TComponent* Owner)
: TForm(Owner)
{
AnsiString ExaName = ExtractFileName(Application->ExeName);
ProductName->Caption = ExaName.SetLength(ExaName.Length()-4);
int aTopPosition = 0;
// if (WhoUseProgram == wupTanjaKvant) Label22->Visible = true;
if (!Label22->Visible) {
BitBtn1->Top = Label22->Top;
ClientHeight = BitBtn1->BoundsRect.Bottom + 4;
}
}
示例10: TForm
//---------------------------------------------------------------------------
__fastcall TEnumWinForm::TEnumWinForm(TComponent* Owner)
: TForm(Owner)
{
TStringList *list = new TStringList();
list->LoadFromFile("winmsgs.txt");
AnsiString str;
int k;
for(int i = 0; i < list->Count; i++)
{
str.SetLength(100);
sscanf(list->Strings[i].c_str(),"%s %X\n",str.c_str(),&k);
MsgComboBox->Items->AddObject(str,(TObject *)k);
}
delete list;
MsgComboBox->ItemIndex = 0;
}
示例11: DoObjectLoad
void __fastcall TTMTimeLineMainForm::DoObjectLoad(TObject* Sender, TStream* Stream, TObject *&AObject)
{
AnsiString S;
int Count;
// Get the length of the string:
Stream->Read(&Count,sizeof(Count));
S.SetLength(Count);
// need we read any more ?
if( Count > 0 )
{
Stream->Read(&S[1],Count);
AObject = new TStringList();
dynamic_cast<TStringList* >(AObject)->Text = S;
}
}
示例12: StringFromFile
AnsiString StringFromFile(const AnsiString FileName, __int64& FileSize)
{
TFileStream* fs = new TFileStream(FileName, fmOpenRead);
AnsiString Result;
try
{
FileSize = fs->Size;
Result.SetLength(FileSize);
if (fs->Size > 0)
fs->Read(Result.c_str(), FileSize);
}
__finally
{
delete fs;
}
return Result;
}
示例13: LoadFromFile
bool TCurve::LoadFromFile(AnsiString asName)
{
DecimalSeparator = '.';
TFileStream *fs;
fs = new TFileStream(asName, fmOpenRead | fmShareCompat);
AnsiString str = "xxx";
int size = fs->Size;
str.SetLength(size);
fs->Read(str.c_str(), size);
str += "";
delete fs;
TQueryParserComp *Parser;
Parser = new TQueryParserComp(NULL);
Parser->TextToParse = str;
Parser->First();
Load(Parser);
delete Parser;
DecimalSeparator = ',';
}
示例14: SaveDataToRegistry
//===========================================================================
void Tform_Main::SaveDataToRegistry()
{
TRegistry *Reg = NULL;
try {
Reg = new TRegistry;
AnsiString appName = ExtractFileName(Application->ExeName);
appName.SetLength(appName.Length() - 4);
Reg->RootKey = HKEY_LOCAL_MACHINE;
Reg->OpenKey("Software\\InnalabsUA\\ccg_QFactor", true);
Reg->WriteFloat("DFT_DeltaFreq", DFT_DeltaFreq);
Reg->WriteInteger("DTF_InterpolationPointsCount", DTF_InterpolationPointsCount);
Reg->WriteInteger("FFT_MaxPointsCount", FFT_MaxPointsCount);
Reg->WriteInteger("SoundCardIndex", SoundCardIndex);
Reg->WriteInteger("FreqSoundCardIndex", FreqSoundCardIndex);
} __finally {
Reg->CloseKey();
if (Reg != NULL)
delete Reg;
}
}
示例15: AddNewFileToMainMenu
//===========================================================================
//===========================================================================
//===========================================================================
//===========================================================================
void AddNewFileToMainMenu(TPopupMenu *PopupMenu, AnsiString FileName, TNotifyEvent NotifyEvent)
{
TRegistry *Reg = new TRegistry;
bool FirstInput = false;
bool FileExist = false;
int Counter = 0;
int posFileNameInMenu = -1;
AnsiString appName = ExtractFileName(Application->ExeName); appName.SetLength(appName.Length() - 4);
try {
Reg->RootKey = HKEY_LOCAL_MACHINE; /// ---- Находитться в Uses Windows
Reg->OpenKey("Software\\Digital Systems & Technologies\\" + appName, true); //create a new key >> .ext
//-------------------
if (FileName == "Load") {
for ( int i = 0; i < CountFileName; i++){
FileNameStackArray[i] = "";
FileNameStackArray[i] = Reg->ReadString("FileName"+IntToStr(i+1));
if (FileNameStackArray[i] != "") {
Counter = Counter + 1;
addMenuItem (Counter, PopupMenu, "&"+IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent);
FirstInput = true;
}
}
if (FirstInput) addMenuItem (Counter + 1,PopupMenu,"-", NULL);
} else {
// --- Проверка на повтор файла -----------
for ( int i = 0; i < CountFileName; i++)
if (FileName == FileNameStackArray[i]) {
FileExist = true;
FileNameStackArray[i] = "";
posFileNameInMenu = i;
}
// -------- Если файл уже существует то удаляем его из списка, сортируем список
if (FileExist) {
for ( int i = posFileNameInMenu; i < CountFileName - 1; i++ ) {
FileNameStackArray[i] = FileNameStackArray[i+1];
}
FileNameStackArray[CountFileName - 1] = "";
}
// ----- Добавляем в "Стек" ---------
for ( int i = CountFileName - 1; i > 0; i--)
if (FileNameStackArray[i-1].data() != NULL)
FileNameStackArray[i] = FileNameStackArray[i-1];
FileNameStackArray[0] = FileName;
// ---- Удаляю все файлы с менюхи ---------
for ( int i = PopupMenu->Items->Count-1; i >= 0; i--)
if (PopupMenu->Items->Items[i]->Name[1] == 'F')
delete PopupMenu->Items->Items[i];
// ---- Добавляю новые файлы в менюху ------
Counter = 0;
for ( int i = 0; i < CountFileName - 1; i++ ) {
if (FileNameStackArray[i] != "") {
Counter = Counter + 1;
addMenuItem (Counter, PopupMenu, "&" + IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent);
}
}
// ---- Добавляю черту ------
addMenuItem (Counter + 1,PopupMenu,"-", NULL);
}
// ---- Записываю в Реестр -------
for ( int i = 0; i < CountFileName; i++)
Reg->WriteString("FileName" + IntToStr(i+1), FileNameStackArray[i]);
//-------------------
Reg->CloseKey();
} __finally {
delete Reg;
}
}