小编Mig*_*l E的帖子

使用Objective-C在iOS中的NSMutableDictionary中添加值

我正在开始objective-c开发,我想问一下实现键和值列表的最佳方法.

在Delphi中有类TDictionary,我使用它是这样的:

myDictionary : TDictionary<string, Integer>;

bool found = myDictionary.TryGetValue(myWord, currentValue);
if (found)
{
    myDictionary.AddOrSetValue(myWord, currentValue+1);
} 
else
{
    myDictionary.Add(myWord,1);
}
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做objective-c?是否有与上述相同的功能AddOrSetValue() or TryGetValue()

谢谢.

objective-c nsmutabledictionary ios

16
推荐指数
3
解决办法
8万
查看次数

检查字符是否是Delphi中的字母(Unicode)

在Delphi中是否有预定义的字符集,以检查字符是否是字母?

在Cocoa我使用类似的东西

if ([[NSCharacterSet whitespaceCharacterSet] characterIsMember:character])
Run Code Online (Sandbox Code Playgroud)

我知道我可以在德尔福做

if c in ['A'..'Z'] then
Run Code Online (Sandbox Code Playgroud)

但这会涵盖Á,À,Ú,É,......等外国人强调的角色吗?

在Delphi中检查这个的最有效方法是什么.我需要检查字符串是否完全由字母组成.

delphi pascal delphi-xe

12
推荐指数
1
解决办法
8485
查看次数

从Delphi获取oData服务

如何从Delphi使用oData webservice(我正在尝试与新的Bing Search Azure API进行交互)?在Delphi中几乎没有任何信息可以做到这一点.这里有一篇文章,但从Delphi的角度来看,它没有多大帮助解释如何使用这样的服务.有谁可以提供一个简单的例子?

delphi odata delphi-xe

10
推荐指数
1
解决办法
2492
查看次数

修剪具有特定字符集的字符串

Delphi中的函数是否等同于Cocoa stringByTrimmingCharactersInSet

我需要的是消除在字符串的开头或结尾找到的字符集中包含的所有字符.可以没有,一个或多个开始或结束字符串......

在Delphi中最有效的方法是什么?

delphi delphi-xe

5
推荐指数
1
解决办法
604
查看次数

在网页中显示PDF并以编程方式滚动

在用户文本搜索之后,我已经构建了一个搜索引擎来查找文档中最相关的短语.处理完毕后,我有一个短语文本列表.我现在需要的是将它们显示给用户,显示原始源PDF并将其滚动到找到原始短语的页面.最好的情况是强调它,但是现在滚动就足够了.

我正在使用PHP和Javascript.

任何人都可以指出我这样做的方法吗?有没有可用的框架?

欢迎任何提示.

html javascript php pdf

5
推荐指数
1
解决办法
6063
查看次数

在将TDictionary排序成数组后正确处理TDictionary的方法

我有像TDictionary这样的

target_results : TDictionary<longint,double>;
Run Code Online (Sandbox Code Playgroud)

填充后我需要对结果进行排序.我是这样做的

type
  TSearchResult = TPair<longint,double>;

var
 target_results_array : TArray<TSearchResult>;

target_results_array:= target_results.ToArray;
TArray.Sort<TSearchResult>(best_knowledge_search_results,
                    TComparer<TSearchResult>.Construct(
                              function(const L, R: TSearchResult): Integer
                              begin
                                if L.Value < R.Value then Result := 1 else if L.Value > R.Value then Result := -1 else Result := 0;
                              end
                    ));
Run Code Online (Sandbox Code Playgroud)

这一切都按预期工作.我的问题是如何在没有任何泄漏的情况下处理TDictionary和TArray?目前我正在做

target_results.Free;
Run Code Online (Sandbox Code Playgroud)

delphi memory-management tdictionary delphi-xe

5
推荐指数
1
解决办法
410
查看次数

对TDictionary进行排序

我对Generic Collections没有经验.我需要对TDictionary进行排序.

type TSearchResult = TPair<Integer,double>;

var
   target_results : TDictionary<Integer, double>;
   session_search_results : array[0..max_searches] of TArray<TSearchResult>;
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码进行排序

   session_search_results[session_search_id]:= target_results.ToArray;
   TArray.Sort<TSearchResult>(session_search_results[session_search_id],
                    TComparer<TSearchResult>.Construct(
                              function(const L, R: TSearchResult): Integer
                              begin
                                 Result := Round(R.Value - L.Value);
                              end
                    ));
Run Code Online (Sandbox Code Playgroud)

为什么我会收到访问冲突?我究竟做错了什么?

补充:

如果我用数组遍历数组

 for i:= 0 to Length(session_search_results[session_search_id])-1 do
      MyDebug(IntToStr(session_search_results[session_search_id][i].Key)+' = value = '
            + FloatToStr(session_search_results[session_search_id][i].Value));
Run Code Online (Sandbox Code Playgroud)

我得到一个输出:

Debug Output: ==>CoreSearchText: array length=8<== Process TestApp.exe (2536)
Debug Output: ==>100007 = value = 19,515<== Process TestApp.exe (2536)
Debug Output: ==>100003 = value = 2,4<== Process TestApp.exe (2536)
Debug …
Run Code Online (Sandbox Code Playgroud)

delphi sorting generics dictionary delphi-xe

4
推荐指数
1
解决办法
4793
查看次数

自上而下迭代泛型集合(TDictionary)

我有一个TDictionary.它充满了广泛的循环.当循环结束时,我需要检索具有更多分数(整数)的10个键(字符串).实现这一目标的最有效方法是什么?

在Objective-C(Cocoa)中,我这样做:

NSArray *top_words_sorted_array = [top_words_dictionary keysSortedByValueUsingSelector:@selector(compare:)];
Run Code Online (Sandbox Code Playgroud)

然后迭代新排序的数组.我怎么能在Delphi中做到这一点?

delphi sorting collections delphi-xe

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

使用常规程序处理类事件(Delphi)

我在一个简单的过程(不是类中的方法)内以编程方式创建数据库连接对象.

mydb:= TUniConnection.Create(nil);
mydb.Database:= knowledge_db_name;
mydb.LoginPrompt:= False;
mydb.Username:= aaa;
mydb.Password:= bbb;
Run Code Online (Sandbox Code Playgroud)

现在我需要处理错误和与其他程序断开连接.当我尝试做的时候:

mydb.OnError:= OnConnectionError;
mydb.OnConnectionLost:= OnConnectionLost;
Run Code Online (Sandbox Code Playgroud)

编译告诉我

[DCC Error] test.pas(373): E2009 Incompatible types: 'method pointer and regular procedure'
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?以下是事件过程的定义:

procedure OnConnectionError(Sender: TObject; E: EDAError; var Fail: Boolean);
procedure OnConnectionLost(Sender: TObject; Component: TComponent; ConnLostCause: TConnLostCause; var RetryMode: TRetryMode);
Run Code Online (Sandbox Code Playgroud)

delphi events pascal delphi-xe

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

在XML中提取值

我需要解析以下XML:

<?xml version="1.0" encoding="UTF-8" ?>
<revista numero="2226" data="03/09/2013">
  <processo numero="902987089">
    <despachos>
      <despacho codigo="IPAS139"/>
    </despachos>
    <titulares>
      <titular nome-razao-social="AAAAA" pais="BR" uf="PR"/>
    </titulares>
  </processo>
  <processo numero="902812165">
    <despachos>
      <despacho codigo="IPAS029"/>
    </despachos>
    <titulares>
      <titular nome-razao-social="XXXX" pais="BR" uf="SC"/>
    </titulares>
(...)
Run Code Online (Sandbox Code Playgroud)

我对XML没有任何经验.我IXMLDocument在Delphi中使用.

LNodeElement := LDocument.ChildNodes.FindNode('revista');
(...)
for I := 0 to LNodeElement.ChildNodes.Count - 1 do
(...)
Run Code Online (Sandbox Code Playgroud)

我的问题是我如何才能到达标签numero内的属性值<processo>?但如果一个善良的灵魂可以分享一个小例子,那将是最受欢迎的.

xml delphi delphi-xe

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