示例#1
0
void splittext(const char *text, u32t width, TStrings &lst, u32t flags) {
   lst.Clear();
   if (!text || width<8) return;
   const char *ps = text, *pps;
   char    softcr = flags&SplitText_HelpMode?'&':0;
   int         ln = 0;
   spstr linehead;
   lst.Add(spstr());
   do {
      while (*ps && (strchr(AllowSet,*ps) || *ps==softcr)) {
         register char cr=*ps++;
         if (cr!=' ') {
            if (cr==softcr) {
               pps = ps;
               if (*pps) pps++;
               while (*pps==' ' || *pps=='\t') pps++;
               /* get 1 char after eol and all spaces after it and use result
                  as a header for all next lines until real cr */
               linehead = spstr(ps, pps-ps).expandtabs(4);
               ps = pps;
            } else {
               lst.Add(spstr());
               if (cr=='\r' && *ps=='\n') ps++;
               linehead.clear();
               if (lst[ln].lastchar()==' ') lst[ln].dellast();
               ln++;
            }
         }
      }
      if (*ps==0) break;
      pps = strpbrk(ps, softcr ? CarrySet AllowSet "&" : CarrySet AllowSet);
      int carry = pps&&strchr(CarrySet,*pps)?1:0;
      spstr curr(ps,pps?pps-ps+carry:0), sum;
      sum = lst[ln]+curr;
      sum.expandtabs(4);

      if ((flags&SplitText_NoAnsi?strlen:str_length)(sum())<width-2)
         lst[ln]=sum;
      else {
         lst.Add(linehead+curr);
         if (lst[ln].lastchar()==' ') lst[ln].dellast();
         ln++;
      }
      if (!carry||pps&&pps[1]==' ') lst[ln]+=' ';
      ps=pps;
      if (carry) ps++;
   } while (pps);
}
void TGridModeDemoMainForm::SortPattern(TcxGridDBDataController *ADataController)
{
    TcxGridDBTableView *AView = (TcxGridDBTableView*)ADataController->GridView;
    TStrings *ASortList = new TStringList();
    try{
      AView->BeginUpdate();
      String AOrder, AFieldName;
      int AIndex;
      for (int I = 0; I < AView->SortedItemCount; I++){
        AIndex = ADataController->GetSortingItemIndex(I);
        AFieldName = AView->Columns[AIndex]->DataBinding->FieldName;
        if (AView->Columns[AIndex]->SortOrder == soAscending)
          AOrder = " ASC, ";
        else
          AOrder = " DESC, ";
        ASortList->Add(AFieldName + AOrder);
      }
      GridModeDemoDataDM->
        ApplySortToQuery((TQuery*)ADataController->DataSet, ASortList);
    }
    __finally{
      delete ASortList;
      AView->EndUpdate();
    }
}
示例#3
0
void __fastcall TEditTiffForm::SetupPageComboBox(int count, int start) {
//-------------------------------------------------------------------------------
//                          Заполняет PageComboBox                              |
// Если start == -1, то не меняет ItemIndex                                     |
//-------------------------------------------------------------------------------
    TStrings *items = PageComboBox->Items;
    int i;
    char buf[50];

    items->Clear();
    for (i = 1; i <= count; i++) {
        sprintf(buf, "%d / %d", i, count);
        items->Add(buf);
    }

    InsideChange = true;
    ScrollBar1->Max = count;
    if (start >= 0) {
        PageComboBox->ItemIndex = start;
        ScrollBar1->Position = start;
    } else if (PageComboBox->ItemIndex == -1) {
        PageComboBox->ItemIndex = 0;
        ScrollBar1->Position = 0;
    }

    EnumTiffPages();
    InsideChange = false;
}
示例#4
0
//---------------------------------------------------------------------------
void __fastcall TSup1011::addItensExecute(TObject *Sender)
{
	TStrings *SQL = new TStringList();
	SQL->Add("SELECT p.cod_produto, p.den_produto, p.cod_unid_medida, 0 val_produto");
	SQL->Add("FROM tbl_produto p");
	SQL->Add("WHERE p.cod_familia = :cod_familia");
	SQL->Add("AND p.ies_ativo = 'S'");
	SQL->Add("ORDER BY p.cod_produto");
	TSup1004 *Sup1004 = new TSup1004(Application);
	Sup1004->OnConfirmList = &addItensConfirm;
	Sup1004->QyCnsProduto->SQL->Assign(SQL);
   Sup1004->edtQtd->Text = '1';
   Sup1004->edtQtd->Visible = false;
   Sup1004->lbQtde->Visible = false;
	Sup1004->ShowModal();
   delete Sup1004;
	delete SQL;
}
示例#5
0
TStrings * ExceptionToMoreMessages(Exception * E)
{
  TStrings * Result = nullptr;
  UnicodeString Message;
  if (ExceptionMessage(E, Message))
  {
    Result = new TStringList();
    Result->Add(Message);
    ExtException * ExtE = dyn_cast<ExtException>(E);
    if ((ExtE != nullptr) && (ExtE->GetMoreMessages() != nullptr))
    {
      Result->AddStrings(ExtE->GetMoreMessages());
    }
  }
  return Result;
}
示例#6
0
TStrings * ExceptionToMoreMessages(Exception * E)
{
  TStrings * Result = nullptr;
  UnicodeString Message;
  if (ExceptionMessage(E, Message))
  {
    Result = new TStringList();
    Result->Add(Message);
    ExtException * ExtE = NB_STATIC_DOWNCAST(ExtException, E);
    if ((ExtE != nullptr) && (ExtE->GetMoreMessages() != nullptr))
    {
      Result->AddStrings(ExtE->GetMoreMessages());
    }
  }
  return Result;
}
示例#7
0
//---------------------------------------------------------------------------
void __fastcall TSynchronizeChecklistDialog::CustomCommandsButtonClick(
  TObject * /*Sender*/)
{
  TStrings * LocalFileList = new TStringList();
  TStrings * RemoteFileList = new TStringList();
  try
  {
    TListItem * Item = ListView->Selected;
    assert(Item != NULL);

    while (Item != NULL)
    {
      const TSynchronizeChecklist::TItem * ChecklistItem =
        static_cast<const TSynchronizeChecklist::TItem *>(Item->Data);

      assert((ChecklistItem->Action == TSynchronizeChecklist::saUploadUpdate) ||
             (ChecklistItem->Action == TSynchronizeChecklist::saDownloadUpdate));
      assert(ChecklistItem->RemoteFile != NULL);

      UnicodeString LocalPath =
        IncludeTrailingBackslash(ChecklistItem->Local.Directory) +
        ChecklistItem->Local.FileName;

      LocalFileList->Add(LocalPath);

      UnicodeString RemotePath =
        UnixIncludeTrailingBackslash(ChecklistItem->Remote.Directory) +
        ChecklistItem->Remote.FileName;

      RemoteFileList->AddObject(RemotePath, ChecklistItem->RemoteFile);

      Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
    }
  }
  catch(...)
  {
    delete LocalFileList;
    delete RemoteFileList;
    throw;
  }

  assert(FOnCustomCommandMenu != NULL);
  FOnCustomCommandMenu(CustomCommandsButton,
    CalculatePopupRect(CustomCommandsButton), LocalFileList, RemoteFileList);
}
示例#8
0
//---------------------------------------------------------------------------
int get_userpass_input(prompts_t * p, unsigned char * /*in*/, int /*inlen*/)
{
  assert(p != NULL);
  TSecureShell * SecureShell = reinterpret_cast<TSecureShell *>(p->frontend);
  assert(SecureShell != NULL);

  int Result;
  TStrings * Prompts = new TStringList();
  TStrings * Results = new TStringList();
  try
  {
    for (int Index = 0; Index < int(p->n_prompts); Index++)
    {
      prompt_t * Prompt = p->prompts[Index];
      Prompts->AddObject(Prompt->prompt, (TObject *)(FLAGMASK(Prompt->echo, pupEcho)));
      // this fails, when new passwords do not match on change password prompt,
      // and putty retries the prompt
      assert(Prompt->resultsize == 0);
      Results->Add(L"");
    }

    if (SecureShell->PromptUser(p->to_server, p->name, p->name_reqd,
          p->instruction, p->instr_reqd, Prompts, Results))
    {
      for (int Index = 0; Index < int(p->n_prompts); Index++)
      {
        prompt_t * Prompt = p->prompts[Index];
        prompt_set_result(Prompt, AnsiString(Results->Strings[Index]).c_str());
      }
      Result = 1;
    }
    else
    {
      Result = 0;
    }
  }
  __finally
  {
    delete Prompts;
    delete Results;
  }

  return Result;
}
示例#9
0
//---------------------------------------------------------------------------
void __fastcall TPropertiesDialog::LoadRemoteTokens(TComboBox * ComboBox,
  const TRemoteTokenList * List)
{
  TStrings * Items = ComboBox->Items;
  Items->BeginUpdate();
  try
  {
    Items->Clear();
    if (List != NULL)
    {
      int Count = List->Count();
      for (int Index = 0; Index < Count; Index++)
      {
        Items->Add(LoadRemoteToken(*List->Token(Index)));
      }
    }
  }
  __finally
  {
    Items->EndUpdate();
  }
}
示例#10
0
//---------------------------------------------------------------------------
bool __fastcall TLocationProfilesDialog::AddAsBookmark(TObject * Sender, bool Initial)
{
  TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  TTreeView * ProfilesView = GetProfilesView(Sender);

  assert(!LocalDirectory.IsEmpty() || !RemoteDirectory.IsEmpty());

  bool Result;
  UnicodeString BookmarkName;
  if ((OperationSide == osLocal && !LocalDirectory.IsEmpty()) ||
      RemoteDirectory.IsEmpty())
  {
    BookmarkName = LocalDirectory;
  }
  else
  {
    BookmarkName = RemoteDirectory;
  }

  TTreeNode * Selected = ProfilesView->Selected;
  TBookmark * SelectedBookmark = NULL;
  UnicodeString SelectedNode;
  if (Selected != NULL)
  {
    assert(!Initial);
    SelectedBookmark = (TBookmark *)Selected->Data;
    if (SelectedBookmark != NULL)
    {
      SelectedNode = SelectedBookmark->Node;
    }
    else
    {
      SelectedNode = Selected->Text;
    }
  }

  TStrings * PeerBookmarks = new TStringList();
  try
  {
    for (int Index = 0; Index < BookmarkList->Count; Index++)
    {
      TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
      if (Bookmark->Node == SelectedNode)
      {
        PeerBookmarks->Add(Bookmark->Name);
      }
    }

    TBookmarkNameDialog * Dialog = new TBookmarkNameDialog(PeerBookmarks, Initial);
    try
    {
      bool Shared = WinConfiguration->UseSharedBookmarks;
      Result = Dialog->Execute(BookmarkName, Shared);
      if (Result)
      {
        if (Initial)
        {
          WinConfiguration->UseSharedBookmarks = Shared;
          BookmarkList = GetBookmarkList(GetProfilesSheet());
          ProfilesView = GetProfilesView(GetProfilesSheet());
        }

        TBookmark * Bookmark = BookmarkList->FindByName(SelectedNode, BookmarkName);
        if (Bookmark != NULL)
        {
          Bookmark->Local = LocalDirectory;
          Bookmark->Remote = RemoteDirectory;

          for (int Index = 0; Index < ProfilesView->Items->Count; Index++)
          {
            TTreeNode * Node = ProfilesView->Items->Item[Index];
            if (Node->Data == Bookmark)
            {
              Selected = Node;
              break;
            }
          }
        }
        else
        {
          Bookmark = new TBookmark();
          Bookmark->Name = BookmarkName;
          Bookmark->Local = LocalDirectory;
          Bookmark->Remote = RemoteDirectory;
          if (SelectedBookmark != NULL)
          {
            Bookmark->Node = SelectedBookmark->Node;
            BookmarkList->InsertBefore(SelectedBookmark, Bookmark);
            Selected = ProfilesView->Items->InsertObject(Selected, BookmarkText(Bookmark), Bookmark);
          }
          else if ((Selected != NULL) && (SelectedBookmark == NULL))
          {
            // must be a folder
            assert(!Selected->Parent); // more than one level of folders is not supported
            Bookmark->Node = Selected->Text;
            BookmarkList->Add(Bookmark);
            Selected = ProfilesView->Items->AddChildObject(Selected, BookmarkText(Bookmark), Bookmark);
          }
          else
          {
            BookmarkList->Add(Bookmark);
            Selected = ProfilesView->Items->AddObject(NULL, BookmarkText(Bookmark), Bookmark);
          }
        }
        ProfilesView->Selected = Selected;
      }
    }
    __finally
    {
      delete Dialog;
    }
  }
  __finally
  {
    delete PeerBookmarks;
  }

  UpdateControls();
  return Result;
}
示例#11
0
/// create list from array of char*
str_list* _std str_fromptr(char **list, int size) {
   TStrings lst;
   if (list&&size>0)
      while (size--) lst.Add(*list++);
   return str_getlist_local(lst.Str);
}