小编siw*_*mas的帖子

使用sprintf动态设置精度

使用sprintf和一般语法"%A.B"我可以这样做:

double a = 0.0000005l;
char myNumber[50];
sprintf(myNumber,"%.2lf",a);
Run Code Online (Sandbox Code Playgroud)

我可以在格式字符串中动态设置A和B吗?

c printf format-string

7
推荐指数
1
解决办法
709
查看次数

在Delphi中有效地填充组合框

需要在TComboBox中添加许多项目(超过10k)(我知道TComboBox不应该包含很多项目,但不能由我来改变它)而不添加重复项.所以我需要在添加之前搜索完整列表.我想避免使用TComboBox.items.indexof,因为我需要二进制搜索,但二进制查找在TStrings中不可用.

所以我创建了一个临时的Tstringlist,设置排序为true并使用find.但现在将临时Tstringlist分配回TComboBox.Items

(myCB.Items.AddStrings(myList)) 
Run Code Online (Sandbox Code Playgroud)

复制整个列表真的很慢.有没有办法移动列表而不是复制它?或者以其他方式高效填充我的TComboBox?

delphi combobox delphi-xe3

4
推荐指数
2
解决办法
1509
查看次数

在Delphi中取消引用和分配指针的语法

需要实现一个接口指针传递的接口方法,并且需要取消引用指针并为其分配OleVariant.这是什么语法?

// Code I have no access to change
function GetEntry: string;
var
  value: OleVariant;
begin
  Entry(@value);  
  Result := VarToStr(value);
end;

// My code  
procedure Entry(Value: Pointer);
begin
  Value^ := ??? // Not sure whats the syntax here in order to assign an OleVariant
end
Run Code Online (Sandbox Code Playgroud)

delphi pointers

3
推荐指数
1
解决办法
258
查看次数

什么时候在delphi中使用is运算符是正确的?

在下面的情况下,我如何测试一个非零的TObject不包含特定类的对象?

procedure TForm7.testme;
var
    mystring: string;
    obj: TObject;
begin
    mystring := 'asd';
    obj := TObject(mystring);

    if assigned(obj) then
        if obj is TestClass then // --> this is failing
        // ...
end;
Run Code Online (Sandbox Code Playgroud)

delphi

2
推荐指数
1
解决办法
590
查看次数

未调用std :: unique_ptr中的自定义删除器

示例没有意义,但仍然无法解释为什么调用自定义删除器.

在得到答案之后,我编辑了我的代码,因此myPsmartP超出范围之前不是null

int * myP = NULL;

{ 
   std::unique_ptr<int, std::function<void(int*)>> smartP(myP, [](int * a) {
        *a = 8; // Custom deleter that is trying to dereference NULL never called
   }); 

   int a = 9;       
   myP = &a;

} // smartP goes out of scope, I expect custom deleter to be called
Run Code Online (Sandbox Code Playgroud)

c++ unique-ptr c++11

2
推荐指数
1
解决办法
401
查看次数

标签 统计

delphi ×3

c ×1

c++ ×1

c++11 ×1

combobox ×1

delphi-xe3 ×1

format-string ×1

pointers ×1

printf ×1

unique-ptr ×1